2024-07-03 23:34:31 +02:00
|
|
|
use camino::Utf8PathBuf;
|
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use hayagriva::Library;
|
2024-04-13 15:26:52 +02:00
|
|
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Renderable};
|
2024-07-03 23:34:31 +02:00
|
|
|
use serde::Deserialize;
|
2024-04-28 00:26:19 +02:00
|
|
|
|
2024-07-03 23:34:31 +02:00
|
|
|
use crate::pipeline::{Content, Sack};
|
2024-04-21 11:45:19 +02:00
|
|
|
use crate::text::md::Outline;
|
2024-07-03 23:34:31 +02:00
|
|
|
use crate::{Linkable, LinkDate};
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-07-03 23:34:31 +02:00
|
|
|
/// Represents a simple post.
|
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
|
|
|
pub(crate) struct Post {
|
|
|
|
pub(crate) title: String,
|
|
|
|
#[serde(with = "super::isodate")]
|
|
|
|
pub(crate) date: DateTime<Utc>,
|
|
|
|
pub(crate) desc: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Content for Post {
|
|
|
|
fn parse(data: &str, lib: Option<&Library>) -> (Outline, String, Option<Vec<String>>) {
|
|
|
|
crate::text::md::parse(data, lib)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn transform<'f, 'm, 's, 'html, T>(
|
|
|
|
&'f self,
|
|
|
|
content: T,
|
|
|
|
outline: Outline,
|
|
|
|
sack: &'s Sack,
|
|
|
|
bib: Option<Vec<String>>,
|
|
|
|
) -> impl Renderable + 'html
|
|
|
|
where
|
|
|
|
'f: 'html,
|
|
|
|
'm: 'html,
|
|
|
|
's: 'html,
|
|
|
|
T: Renderable + 'm,
|
|
|
|
{
|
|
|
|
post(self, content, outline, bib, sack)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_link(&self, path: Utf8PathBuf) -> Option<Linkable> {
|
|
|
|
Some(Linkable::Date(LinkDate {
|
|
|
|
link: crate::Link {
|
|
|
|
path,
|
|
|
|
name: self.title.to_owned(),
|
|
|
|
desc: self.desc.to_owned(),
|
|
|
|
},
|
|
|
|
date: self.date.to_owned(),
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-05-02 15:26:08 +02:00
|
|
|
pub fn post<'f, 'm, 's, 'html, T>(
|
|
|
|
fm: &'f Post,
|
2024-04-21 11:45:19 +02:00
|
|
|
content: T,
|
|
|
|
outline: Outline,
|
2024-04-28 00:26:19 +02:00
|
|
|
bib: Option<Vec<String>>,
|
2024-05-02 15:26:08 +02:00
|
|
|
sack: &'s Sack,
|
|
|
|
) -> impl Renderable + 'html
|
2024-04-13 15:26:52 +02:00
|
|
|
where
|
2024-05-02 15:26:08 +02:00
|
|
|
'f: 'html,
|
|
|
|
'm: 'html,
|
|
|
|
's: 'html,
|
|
|
|
T: Renderable + 'm
|
2024-04-13 15:26:52 +02:00
|
|
|
{
|
|
|
|
let main = maud_move!(
|
|
|
|
main .wiki-main {
|
|
|
|
|
|
|
|
// Slide in/out for mobile
|
|
|
|
input #wiki-aside-shown type="checkbox" hidden;
|
|
|
|
|
|
|
|
aside .wiki-aside {
|
|
|
|
// Slide button
|
|
|
|
label .wiki-aside__slider for="wiki-aside-shown" {
|
|
|
|
img .wiki-icon src="/static/svg/double-arrow.svg" width="24" height="24";
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
(crate::html::misc::show_outline(outline))
|
2024-04-13 15:26:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
article .wiki-article /*class:list={classlist)*/ {
|
|
|
|
header class="markdown" {
|
|
|
|
h1 #top { (fm.title.clone()) }
|
|
|
|
}
|
|
|
|
section .wiki-article__markdown.markdown {
|
|
|
|
(content)
|
|
|
|
}
|
2024-04-28 00:26:19 +02:00
|
|
|
|
|
|
|
@if let Some(bib) = bib {
|
2024-07-03 23:34:31 +02:00
|
|
|
(crate::html::misc::show_bibliography(bib))
|
2024-04-28 00:26:19 +02:00
|
|
|
}
|
2024-04-13 15:26:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2024-07-03 23:34:31 +02:00
|
|
|
crate::html::page(&fm.title, main, sack.get_file())
|
2024-04-13 15:26:52 +02:00
|
|
|
}
|