1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
use crate::{
article_metadata, file_history, get_articles,
markdown::{self},
ArticleMeta,
};
use laby::{frag, html, iter, li, Render};
use std::fs::read_to_string;
pub fn scaffold(title: String, body: impl Render) -> impl Render {
html!(
head!(
meta!(charset = "UTF-8"),
link!(rel = "stylesheet", href = "./style.css"),
title!(format!("{} - metamuffin's blog", title))
),
body!(
nav!(
h2!("metamuffin's blog"),
a!(href = "./index", "index"),
" ",
a!(href = "./feed.atom", "atom")
),
article!(body),
footer!(p!("written by metamuffin, licensed under CC-BY-ND-4.0"))
)
)
}
pub fn article(path: String) -> impl Render {
scaffold(
article_metadata(path.clone().into()).title,
frag!(
laby::raw!(markdown::render(&read_to_string(&path).unwrap())),
hr!(),
p!(
"changes to this article (as recorded with git; visible ",
a!(
href = format!(
"https://codeberg.org/metamuffin/blog/commits/branch/master/content/{path}"
),
"on codeberg"
),
")"
),
pre!(file_history(&path))
),
)
}
pub fn index(root: &str) -> impl Render {
scaffold(
"index".to_string(),
frag!(
p!(
"This is my personal blog. The sources (including all the tooling) are available ",
a!(href = "https://codeberg.org/metamuffin/blog", "on codeberg")
),
ul!(iter!({
get_articles(&root).into_iter().map(
|ArticleMeta {
canonical_name,
date,
title,
..
}| {
li!(
date.to_string(),
": ",
a!(href = format!("./{canonical_name}",), title)
)
},
)
}))
),
)
}
pub fn escape(text: &str) -> String {
text.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("'", "’")
.replace("\"", """)
}
|