diff options
author | metamuffin <metamuffin@disroot.org> | 2022-08-29 22:53:37 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-08-29 22:53:37 +0200 |
commit | 3eb1adfeb8dd477479404a1269c8682e3b4edf12 (patch) | |
tree | 1a4788149dc4b958dee129c28b95553cc3927f16 /code/src/html.rs | |
parent | a4dd9c4944340505962f07853d53ab02f3a02336 (diff) | |
download | metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar.bz2 metamuffin-blog-3eb1adfeb8dd477479404a1269c8682e3b4edf12.tar.zst |
split files
Diffstat (limited to 'code/src/html.rs')
-rw-r--r-- | code/src/html.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/code/src/html.rs b/code/src/html.rs new file mode 100644 index 0000000..bdc9a78 --- /dev/null +++ b/code/src/html.rs @@ -0,0 +1,44 @@ +use crate::{article_metadata, get_articles, markdown::blocks_to_html}; +use laby::{html, iter, li, ul, Render}; +use std::fs::read_to_string; + +pub fn scaffold(title: String, body: impl Render) -> impl Render { + html!( + head!( + link!(rel = "stylesheet", href = "./style.css"), + title!(format!("{} - metamuffin's blog", title)) + ), + body!( + nav!(h2!("metamuffin's blog"), a!(href = "./index.html", "index")), + 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, + laby::raw!(blocks_to_html(markdown::tokenize( + &read_to_string(path).unwrap() + ))), + ) +} + +pub fn index(root: &str) -> impl Render { + scaffold( + "index".to_string(), + ul!(iter!({ + get_articles(&root).into_iter().map(|meta| { + li!( + meta.date.to_string(), + ": ", + a!( + href = format!("./{}", meta.path.to_str().unwrap().replace(".md", ".html")), + meta.title + ) + ) + }) + })), + ) +} |