2024-09-16 23:01:38 +02:00
|
|
|
use camino::Utf8Path;
|
|
|
|
use hauchiwa::{Bibliography, Outline, Sack};
|
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-21 23:02:30 +02:00
|
|
|
|
2024-07-03 23:34:31 +02:00
|
|
|
/// Represents a wiki page
|
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
|
|
|
pub struct Wiki {
|
2024-07-05 13:59:07 +02:00
|
|
|
pub title: String,
|
2024-07-03 23:34:31 +02:00
|
|
|
}
|
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn parse_content(
|
|
|
|
content: &str,
|
|
|
|
sack: &Sack,
|
|
|
|
path: &Utf8Path,
|
|
|
|
library: Option<&Library>,
|
|
|
|
) -> (String, Outline, Bibliography) {
|
|
|
|
crate::text::md::parse(content, sack, path, library)
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-09-15 01:44:37 +02:00
|
|
|
pub fn as_html(
|
|
|
|
meta: &Wiki,
|
|
|
|
parsed: &str,
|
|
|
|
sack: &Sack,
|
|
|
|
outline: Outline,
|
|
|
|
bibliography: Bibliography,
|
|
|
|
) -> String {
|
|
|
|
wiki(meta, parsed, sack, outline, bibliography)
|
|
|
|
}
|
2024-07-03 23:34:31 +02:00
|
|
|
|
2024-07-22 23:08:11 +02:00
|
|
|
fn wiki(
|
|
|
|
matter: &Wiki,
|
|
|
|
parsed: &str,
|
|
|
|
sack: &Sack,
|
2024-07-05 13:59:07 +02:00
|
|
|
_: Outline,
|
2024-07-22 23:08:11 +02:00
|
|
|
bibliography: Bibliography,
|
|
|
|
) -> String {
|
2024-07-05 13:59:07 +02:00
|
|
|
let heading = matter.title.clone();
|
|
|
|
let main = maud_move!(
|
|
|
|
main .wiki-main {
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-07-05 13:59:07 +02:00
|
|
|
// Slide in/out for mobile
|
|
|
|
input #wiki-aside-shown type="checkbox" hidden;
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-07-05 13:59:07 +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";
|
|
|
|
}
|
|
|
|
// Navigation tree
|
|
|
|
section .link-tree {
|
|
|
|
div {
|
|
|
|
(crate::html::misc::show_page_tree(sack, "wiki/**/*.html"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-07-05 13:59:07 +02:00
|
|
|
article .wiki-article /*class:list={classlist)*/ {
|
|
|
|
header class="markdown" {
|
|
|
|
h1 #top { (heading) }
|
|
|
|
}
|
|
|
|
section .wiki-article__markdown.markdown {
|
2024-07-22 23:08:11 +02:00
|
|
|
(Raw(parsed))
|
2024-07-05 13:59:07 +02:00
|
|
|
}
|
2024-04-28 00:26:19 +02:00
|
|
|
|
2024-07-22 23:08:11 +02:00
|
|
|
@if let Some(bib) = bibliography.0 {
|
2024-09-08 19:09:25 +02:00
|
|
|
(crate::html::misc::emit_bibliography(bib))
|
2024-07-05 13:59:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2024-04-13 15:26:52 +02:00
|
|
|
|
2024-09-08 19:09:25 +02:00
|
|
|
crate::html::page(sack, main, matter.title.to_owned(), None)
|
2024-09-15 01:44:37 +02:00
|
|
|
.unwrap()
|
2024-07-22 23:08:11 +02:00
|
|
|
.render()
|
|
|
|
.into()
|
2024-04-13 15:26:52 +02:00
|
|
|
}
|