diff --git a/src/html/head.rs b/src/html/head.rs index 517bada..4b50d57 100644 --- a/src/html/head.rs +++ b/src/html/head.rs @@ -1,4 +1,5 @@ -use hauchiwa::{HashedStyle, Mode, Sack}; +use camino::Utf8Path; +use hauchiwa::{Mode, Sack}; use hypertext::{html_elements, maud_move, Raw, Renderable}; use crate::MyData; @@ -21,9 +22,9 @@ where 's: 'r, { let title = format!("{} | kamoshi.org", title); - let css = sack.get_style("styles").expect("Missing styles"); - let css_r = sack.get_style("reveal").expect("Missing styles"); - let css_p = sack.get_style("leaflet").expect("Missing styles"); + let css = sack.get_styles("styles").expect("Missing styles"); + let css_r = sack.get_styles("reveal").expect("Missing styles"); + let css_p = sack.get_styles("leaflet").expect("Missing styles"); let scripts = match scripts { Some(scripts) => Some(emit_tags_script(sack, scripts)?), @@ -47,9 +48,9 @@ where link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"; link rel="icon" href="/favicon.ico" sizes="any"; - script type="importmap" {(Raw(sack.get_import_map()))} + // script type="importmap" {(Raw(sack.get_import_map()))} - @if matches!(sack.ctx.mode, Mode::Watch) { + @if matches!(sack.get_context().mode, Mode::Watch) { script { (Raw(JS_RELOAD)) } } @@ -59,9 +60,9 @@ where )) } -fn render_style(style: &HashedStyle) -> impl Renderable + '_ { +fn render_style(path: &Utf8Path) -> impl Renderable + '_ { maud_move!( - link rel="stylesheet" href=(style.path.as_str()); + link rel="stylesheet" href=(path.as_str()); ) } @@ -83,11 +84,11 @@ fn emit_tags_script<'a>( fn emit_tag_script<'a>( sack: &'a Sack, - script: &'a str, + alias: &'a str, ) -> Result { - let src = sack - .get_script(script) - .ok_or(format!("Missing script {script}"))?; + let path = sack + .get_script(alias) + .ok_or(format!("Missing script {}", alias))?; - Ok(maud_move!(script type="module" src=(src.path.as_str()) defer {})) + Ok(maud_move!(script type="module" src=(path.as_str()) defer {})) } diff --git a/src/html/home.rs b/src/html/home.rs index ae13b66..f1a22cc 100644 --- a/src/html/home.rs +++ b/src/html/home.rs @@ -43,15 +43,15 @@ fn photo() -> impl Renderable { fn latest(sack: &Sack) -> impl Renderable { let links = { let mut list = sack - .get_meta::("**") + .get_content_list::("**") .into_iter() - .map(|(path, meta)| LinkDate { + .map(|query| LinkDate { link: Link { - path: Utf8Path::new("/").join(path), - name: meta.title.clone(), - desc: meta.desc.clone(), + path: Utf8Path::new("/").join(query.slug), + name: query.meta.title.clone(), + desc: query.meta.desc.clone(), }, - date: meta.date, + date: query.meta.date, }) .collect::>(); list.sort_by(|a, b| b.date.cmp(&a.date)); diff --git a/src/html/misc.rs b/src/html/misc.rs index a616301..0f1688c 100644 --- a/src/html/misc.rs +++ b/src/html/misc.rs @@ -78,20 +78,23 @@ impl TreePage { } /// Render the page tree -pub(crate) fn show_page_tree<'a>(sack: &'a MySack, glob: &'a str) -> impl Renderable + 'a { - let tree = - TreePage::from_iter( - sack.get_meta::(glob) - .into_iter() - .map(|(path, meta)| Link { - path: Utf8Path::new("/").join(path.parent().unwrap()), - name: meta.title.clone(), - desc: None, - }), - ); +pub(crate) fn show_page_tree<'a>( + path: &'a Utf8Path, + sack: &'a MySack, + glob: &'a str, +) -> impl Renderable + 'a { + let tree = sack + .get_content_list::(glob) + .into_iter() + .map(|query| Link { + path: Utf8Path::new("/").join(query.slug), + name: query.meta.title.clone(), + desc: None, + }); + let tree = TreePage::from_iter(tree); let parts = { - let mut parts = sack.path.iter().skip(1).collect::>(); + let mut parts = path.iter().skip(1).collect::>(); parts.insert(0, "wiki"); parts }; diff --git a/src/html/mod.rs b/src/html/mod.rs index 84d86fe..8100301 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -68,16 +68,20 @@ pub fn footer<'s, 'html>(sack: &'s MySack) -> impl Renderable + 'html where 's: 'html, { - let copy = format!("Copyright © {} Maciej Jur", &sack.ctx.data.year); + let copy = format!( + "Copyright © {} Maciej Jur", + &sack.get_context().data.year + ); let mail = "maciej@kamoshi.org"; let href = format!("mailto:{}", mail); - let link = Utf8Path::new(&sack.ctx.data.link) + let link = Utf8Path::new(&sack.get_context().data.link) .join("src/commit") - .join(&sack.ctx.data.hash); - let link = match sack.get_file() { - Some(path) => link.join(path), - None => link, - }; + .join(&sack.get_context().data.hash); + + // let link = match sack.get_file() { + // Some(path) => link.join(path), + // None => link, + // }; maud_move!( footer .footer { @@ -91,10 +95,10 @@ where } div .repo { a href=(link.as_str()) { - (&sack.ctx.data.hash) + (&sack.get_context().data.hash) } div { - (&sack.ctx.data.date) + (&sack.get_context().data.date) } } a .right.footer__cc-wrap rel="license" href="http://creativecommons.org/licenses/by/4.0/" { diff --git a/src/html/wiki.rs b/src/html/wiki.rs index 4effb48..0bcfa6a 100644 --- a/src/html/wiki.rs +++ b/src/html/wiki.rs @@ -18,16 +18,18 @@ pub fn as_html( meta: &Wiki, parsed: &str, sack: &MySack, + path: &Utf8Path, outline: Outline, bibliography: Bibliography, ) -> String { - wiki(meta, parsed, sack, outline, bibliography) + wiki(meta, parsed, sack, path, outline, bibliography) } fn wiki( matter: &Wiki, parsed: &str, sack: &MySack, + path: &Utf8Path, _: Outline, bibliography: Bibliography, ) -> String { @@ -46,7 +48,7 @@ fn wiki( // Navigation tree section .link-tree { div { - (crate::html::misc::show_page_tree(sack, "wiki/**/*.html")) + (crate::html::misc::show_page_tree(path, sack, "wiki/**/*.html")) } } } diff --git a/src/main.rs b/src/main.rs index 6ab2599..dfc1b5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::process::Command; use camino::{Utf8Path, Utf8PathBuf}; use chrono::{DateTime, Datelike, Utc}; use clap::{Parser, ValueEnum}; -use hauchiwa::{Collection, Processor, Sack, Website}; +use hauchiwa::{Collection, Sack, Website}; use hypertext::Renderable; use model::{Post, Slideshow, Wiki}; @@ -73,51 +73,11 @@ fn main() { let website = Website::setup() .add_collections(vec![ - Collection::glob_with::( - "content", - "about.md", - ["md"].into(), - Processor { - read_content: crate::html::post::parse_content, - to_html: crate::html::post::as_html, - }, - ), - Collection::glob_with::( - "content", - "posts/**/*", - ["md", "mdx"].into(), - Processor { - read_content: crate::html::post::parse_content, - to_html: crate::html::post::as_html, - }, - ), - Collection::glob_with::( - "content", - "slides/**/*", - ["md", "lhs"].into(), - Processor { - read_content: crate::html::slideshow::parse_content, - to_html: crate::html::slideshow::as_html, - }, - ), - Collection::glob_with::( - "content", - "wiki/**/*", - ["md"].into(), - Processor { - read_content: crate::html::wiki::parse_content, - to_html: crate::html::wiki::as_html, - }, - ), - Collection::glob_with::( - "content", - "projects/flox.md", - ["md"].into(), - Processor { - read_content: crate::html::post::parse_content, - to_html: crate::html::as_html, - }, - ), + Collection::glob_with::("content", "about.md", ["md"].into()), + Collection::glob_with::("content", "posts/**/*", ["md", "mdx"].into()), + Collection::glob_with::("content", "slides/**/*", ["md", "lhs"].into()), + Collection::glob_with::("content", "wiki/**/*", ["md"].into()), + Collection::glob_with::("content", "projects/flox.md", ["md"].into()), ]) .add_scripts(vec![ ("search", "./js/search/dist/search.js"), @@ -126,83 +86,133 @@ fn main() { ("editor", "./js/flox/main.ts"), ("lambda", "./js/flox/lambda.ts"), ]) - .add_virtual( - |sack| crate::html::map(sack).unwrap().render().to_owned().into(), - "map/index.html".into(), - ) - .add_virtual(crate::html::search, "search/index.html".into()) - .add_virtual( - |sack| { + .add_task(|sack| { + let query = sack.get_content::("about").unwrap(); + let (parsed, outline, bib) = + html::post::parse_content(query.content, &sack, query.file, None); + let out_buff = html::post::as_html(query.meta, &parsed, &sack, outline, bib); + vec![(query.slug.join("index.html"), out_buff)] + }) + // Task: generate posts + .add_task(|sack| { + sack.get_content_list::("posts/**/*") + .into_iter() + .map(|query| { + let (parsed, outline, bib) = + html::post::parse_content(query.content, &sack, query.file, None); + let out_buff = html::post::as_html(query.meta, &parsed, &sack, outline, bib); + (query.slug.join("index.html"), out_buff) + }) + .collect() + }) + // Task: generate slides + .add_task(|sack| { + sack.get_content_list::("slides/**/*") + .into_iter() + .map(|query| { + let (parsed, outline, bib) = + html::slideshow::parse_content(query.content, &sack, query.file, None); + let out_buff = + html::slideshow::as_html(query.meta, &parsed, &sack, outline, bib); + (query.slug.join("index.html"), out_buff) + }) + .collect() + }) + // Task: generate wiki + .add_task(|sack| { + sack.get_content_list::("wiki/**/*") + .into_iter() + .map(|query| { + let (parsed, outline, bib) = + html::wiki::parse_content(query.content, &sack, query.file, None); + let out_buff = + html::wiki::as_html(query.meta, &parsed, &sack, query.file, outline, bib); + (query.slug.join("index.html"), out_buff) + }) + .collect() + }) + // Task: generate map + .add_task(|sack| { + vec![( + "map/index.html".into(), + crate::html::map(&sack).unwrap().render().to_owned().into(), + )] + }) + // Task: generate search + .add_task(|sack| vec![("search/index.html".into(), crate::html::search(&sack))]) + // Task: generate home page + .add_task(|sack| { + let data = std::fs::read_to_string("content/index.md").unwrap(); + let (parsed, _, _) = text::md::parse(&data, &sack, "".into(), None); + vec![("index.html".into(), crate::html::home(&sack, &parsed))] + }) + // Task: generate project index + .add_task(|sack| { + vec![( + "projects/index.html".into(), crate::html::to_list( - sack, - sack.get_meta::("projects/**/*.html") + &sack, + sack.get_content_list::("projects/**/*") .into_iter() - .map(|(path, meta)| LinkDate { + .map(|query| LinkDate { link: Link { - path: Utf8Path::new("/").join(path.parent().unwrap()), - name: meta.title.clone(), - desc: meta.desc.clone(), + path: Utf8Path::new("/").join(query.slug), + name: query.meta.title.clone(), + desc: query.meta.desc.clone(), }, - date: meta.date, + date: query.meta.date, }) .collect(), "Projects".into(), - ) - }, - "projects/index.html".into(), - ) - .add_virtual( - |sack| { + ), + )] + }) + // Task: generate post index + .add_task(|sack| { + vec![( + "posts/index.html".into(), crate::html::to_list( - sack, - sack.get_meta::("posts/**/*.html") + &sack, + sack.get_content_list::("posts/**/*") .into_iter() - .map(|(path, meta)| LinkDate { + .map(|query| LinkDate { link: Link { - path: Utf8Path::new("/").join(path.parent().unwrap()), - name: meta.title.clone(), - desc: meta.desc.clone(), + path: Utf8Path::new("/").join(query.slug), + name: query.meta.title.clone(), + desc: query.meta.desc.clone(), }, - date: meta.date, + date: query.meta.date, }) .collect(), "Posts".into(), - ) - }, - "posts/index.html".into(), - ) - .add_virtual( - |sack| { + ), + )] + }) + // Task: generate slideshow index + .add_task(|sack| { + vec![( + "slides/index.html".into(), crate::html::to_list( - sack, - sack.get_meta::("slides/**/*.html") + &sack, + sack.get_content_list::("slides/**/*") .into_iter() - .map(|(path, meta)| LinkDate { + .map(|query| LinkDate { link: Link { - path: Utf8Path::new("/").join(path.parent().unwrap()), - name: meta.title.clone(), - desc: meta.desc.clone(), + path: Utf8Path::new("/").join(query.slug), + name: query.meta.title.clone(), + desc: query.meta.desc.clone(), }, - date: meta.date, + date: query.meta.date, }) .collect(), "Slideshows".into(), - ) - }, - "slides/index.html".into(), - ) - .add_virtual( - |sack| { - let data = std::fs::read_to_string("content/index.md").unwrap(); - let (parsed, _, _) = text::md::parse(&data, sack, "".into(), None); - crate::html::home(sack, &parsed) - }, - "index.html".into(), - ) + ), + )] + }) .finish(); match args.mode { Mode::Build => website.build(MyData::new()), - Mode::Watch => website.watch(MyData::new()), + Mode::Watch => (), //website.watch(MyData::new())), } } diff --git a/src/text/md.rs b/src/text/md.rs index 0050201..dbe452f 100644 --- a/src/text/md.rs +++ b/src/text/md.rs @@ -363,7 +363,7 @@ fn swap_hashed_image<'a>(dir: &'a Utf8Path, sack: &'a MySack) -> impl Fn(Event) id, } => { let rel = dir.join(dest_url.as_ref()); - let img = sack.get_image(&rel); + let img = sack.get_picture(&rel); let hashed = img.map(|path| path.as_str().to_owned().into()); Event::Start(Tag::Image { link_type,