2024-09-16 23:01:38 +02:00
|
|
|
use camino::Utf8Path;
|
2024-07-03 23:34:31 +02:00
|
|
|
use chrono::{DateTime, Utc};
|
2024-09-17 21:43:32 +02:00
|
|
|
use hauchiwa::{Bibliography, Outline};
|
2024-07-03 23:34:31 +02:00
|
|
|
use hayagriva::Library;
|
2024-07-22 23:08:11 +02:00
|
|
|
use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable};
|
2024-07-03 23:34:31 +02:00
|
|
|
use serde::Deserialize;
|
2024-04-28 00:26:19 +02:00
|
|
|
|
2024-09-17 21:43:32 +02:00
|
|
|
use crate::MySack;
|
|
|
|
|
2024-07-03 23:34:31 +02:00
|
|
|
/// Represents a simple post.
|
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2024-09-15 01:44:37 +02:00
|
|
|
pub struct Post {
|
2024-09-16 23:01:38 +02:00
|
|
|
pub title: String,
|
|
|
|
#[serde(with = "super::isodate")]
|
|
|
|
pub date: DateTime<Utc>,
|
|
|
|
pub desc: Option<String>,
|
|
|
|
pub scripts: Option<Vec<String>>,
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn parse_content(
|
2024-09-16 23:01:38 +02:00
|
|
|
content: &str,
|
2024-09-17 21:43:32 +02:00
|
|
|
sack: &MySack,
|
2024-09-16 23:01:38 +02:00
|
|
|
path: &Utf8Path,
|
|
|
|
library: Option<&Library>,
|
2024-09-15 01:44:37 +02:00
|
|
|
) -> (String, Outline, Bibliography) {
|
2024-09-16 23:01:38 +02:00
|
|
|
crate::text::md::parse(content, sack, path, library)
|
2024-09-15 01:44:37 +02:00
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn as_html(
|
2024-09-16 23:01:38 +02:00
|
|
|
meta: &Post,
|
|
|
|
parsed: &str,
|
2024-09-17 21:43:32 +02:00
|
|
|
sack: &MySack,
|
2024-09-16 23:01:38 +02:00
|
|
|
outline: Outline,
|
|
|
|
bibliography: Bibliography,
|
2024-09-15 01:44:37 +02:00
|
|
|
) -> String {
|
2024-09-16 23:01:38 +02:00
|
|
|
post(meta, parsed, sack, outline, bibliography)
|
|
|
|
.unwrap()
|
|
|
|
.render()
|
|
|
|
.into()
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-07-05 13:59:07 +02:00
|
|
|
pub fn post<'s, 'p, 'html>(
|
2024-09-16 23:01:38 +02:00
|
|
|
meta: &'p Post,
|
|
|
|
parsed: &'p str,
|
2024-09-17 21:43:32 +02:00
|
|
|
sack: &'s MySack,
|
2024-09-16 23:01:38 +02:00
|
|
|
outline: Outline,
|
|
|
|
bibliography: Bibliography,
|
2024-09-08 23:07:13 +02:00
|
|
|
) -> Result<impl Renderable + 'html, String>
|
2024-07-05 13:59:07 +02:00
|
|
|
where
|
2024-09-16 23:01:38 +02:00
|
|
|
's: 'html,
|
|
|
|
'p: 'html,
|
2024-04-13 15:26:52 +02:00
|
|
|
{
|
2024-09-16 23:01:38 +02:00
|
|
|
let main = maud_move!(
|
|
|
|
main {
|
|
|
|
(article(&meta.title, parsed, sack, outline, bibliography))
|
|
|
|
}
|
|
|
|
);
|
2024-08-25 12:13:07 +02:00
|
|
|
|
2024-09-16 23:01:38 +02:00
|
|
|
crate::html::page(sack, main, meta.title.clone(), meta.scripts.as_deref())
|
2024-08-25 12:13:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn article<'p, 's, 'html>(
|
2024-09-16 23:01:38 +02:00
|
|
|
title: &'p str,
|
|
|
|
parsed: &'p str,
|
2024-09-17 21:43:32 +02:00
|
|
|
_: &'s MySack,
|
2024-09-16 23:01:38 +02:00
|
|
|
outline: Outline,
|
|
|
|
bibliography: Bibliography,
|
2024-08-25 12:13:07 +02:00
|
|
|
) -> impl Renderable + 'html
|
|
|
|
where
|
2024-09-16 23:01:38 +02:00
|
|
|
's: 'html,
|
|
|
|
'p: 'html,
|
2024-08-25 12:13:07 +02:00
|
|
|
{
|
2024-09-16 23:01:38 +02:00
|
|
|
maud_move!(
|
|
|
|
div .wiki-main {
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-09-16 23:01:38 +02:00
|
|
|
// Slide in/out for mobile
|
|
|
|
input #wiki-aside-shown type="checkbox" hidden;
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-09-16 23:01:38 +02:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
(crate::html::misc::show_outline(outline))
|
|
|
|
}
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-09-16 23:01:38 +02:00
|
|
|
article .wiki-article /*class:list={classlist)*/ {
|
|
|
|
header class="markdown" {
|
|
|
|
h1 #top { (title) }
|
|
|
|
}
|
|
|
|
section .wiki-article__markdown.markdown {
|
|
|
|
(Raw(parsed))
|
|
|
|
}
|
2024-04-28 00:26:19 +02:00
|
|
|
|
2024-09-16 23:01:38 +02:00
|
|
|
@if let Some(bib) = bibliography.0 {
|
|
|
|
(crate::html::misc::emit_bibliography(bib))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2024-04-13 15:26:52 +02:00
|
|
|
}
|