diff --git a/content/posts/lambda-calculus/index.md b/content/posts/lambda-calculus/index.md index 2d3bad8..3cc9abc 100644 --- a/content/posts/lambda-calculus/index.md +++ b/content/posts/lambda-calculus/index.md @@ -3,6 +3,8 @@ title: Lambda calculus is the DNA of all computation date: 2024-09-07T20:32:00.281Z desc: > Lambda calculus can be used to express any computation, but what does it entail? As it turns out first class functions are the single most powerful abstraction. +scripts: + - lambda --- In lambda calculus the entire grammar of the language comprises of just three kinds of expressions diff --git a/src/html/head.rs b/src/html/head.rs index 8ff1c2f..3b01e93 100644 --- a/src/html/head.rs +++ b/src/html/head.rs @@ -13,6 +13,7 @@ pub(crate) fn render_head<'s, 'r>( sack: &'s Sack, title: String, styles: &'s [&str], + js: Option<&'s [String]>, ) -> impl Renderable + 'r where 's: 'r, @@ -44,6 +45,12 @@ where @if matches!(sack.ctx.mode, Mode::Watch) { script { (Raw(JS_RELOAD)) } } + + @if let Some(scripts) = js { + @for script in scripts { + (emit_tag_script(sack, script)) + } + } ) } @@ -52,3 +59,11 @@ fn render_style(style: &HashedStyle) -> impl Renderable + '_ { link rel="stylesheet" href=(style.path.as_str()); ) } + +fn emit_tag_script<'a>(sack: &'a Sack, script: &'a str) -> impl Renderable + 'a { + let src = sack.get_script(script).unwrap().path.as_str(); + + maud_move!( + script type="module" src=(src) defer {} + ) +} diff --git a/src/html/home.rs b/src/html/home.rs index a1d60c3..f089e87 100644 --- a/src/html/home.rs +++ b/src/html/home.rs @@ -81,5 +81,5 @@ pub(crate) fn home(sack: &Sack, main: &str) -> String { } ); - crate::html::page(sack, main, "Home".into()).render().into() + crate::html::page(sack, main, "Home".into(), None).render().into() } diff --git a/src/html/list.rs b/src/html/list.rs index adc4d08..a2fb691 100644 --- a/src/html/list.rs +++ b/src/html/list.rs @@ -27,7 +27,7 @@ where } ); - page(sack, list, title) + page(sack, list, title, None) } fn section(year: i32, group: &[LinkDate]) -> impl Renderable + '_ { diff --git a/src/html/misc.rs b/src/html/misc.rs index 40d1e83..2565fed 100644 --- a/src/html/misc.rs +++ b/src/html/misc.rs @@ -24,14 +24,13 @@ pub(crate) fn show_outline(outline: Outline) -> impl Renderable { ) } -/// Render the bibliography for a document -pub(crate) fn show_bibliography(bib: Vec) -> impl Renderable { +pub(crate) fn emit_bibliography(bib: Vec) -> impl Renderable { maud_move!( - section .markdown { + section .bibliography.markdown { h2 { "Bibliography" } - ol .bibliography { + ol { @for item in bib { li { (Raw(item)) diff --git a/src/html/mod.rs b/src/html/mod.rs index 4c557ca..09e3ec9 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -113,6 +113,7 @@ fn bare<'s, 'p, 'html>( sack: &'s Sack, main: impl Renderable + 'p, title: String, + js: Option<&'s [String]>, ) -> impl Renderable + 'html where 's: 'html, @@ -121,7 +122,7 @@ where maud_move!( (Raw("")) html lang="en" { - (head::render_head(sack, title, &[])) + (head::render_head(sack, title, &[], js)) body { (main) @@ -145,13 +146,14 @@ where (main) ); - bare(sack, main, title) + bare(sack, main, title, None) } fn page<'s, 'p, 'html>( sack: &'s Sack, main: impl Renderable + 'p, title: String, + js: Option<&'s [String]>, ) -> impl Renderable + 'html where 's: 'html, @@ -163,7 +165,7 @@ where (footer(sack)) ); - bare(sack, main, title) + bare(sack, main, title, js) } pub(crate) fn to_list(sack: &Sack, list: Vec, title: String) -> String { @@ -203,18 +205,17 @@ where ) } -pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> impl Renderable + 'html -where - 's: 'html, -{ +pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String { page( sack, maud!( main #app {} - script type="module" { (Raw("import 'search';")) } ), String::from("Search"), + Some(&["search".into()]) ) + .render() + .into() } @@ -244,7 +245,7 @@ impl Content for Flox { outline: Outline, bibliography: Bibliography, ) -> String { - flox(&self.title, parsed, sack, outline, bibliography).render().into() + flox(&self.title, parsed, sack, outline, bibliography) } fn as_link(&self, path: Utf8PathBuf) -> Option { @@ -260,19 +261,15 @@ impl Content for Flox { } pub(crate) fn flox<'p, 's, 'html>( - title: &'p str, - parsed: &'p str, - sack: &'s Sack, + title: &str, + parsed: &str, + sack: &Sack, outline: Outline, bibliography: Bibliography, -) -> impl Renderable + 'html -where - 'p: 'html, - 's: 'html, -{ +) -> String { page( sack, - maud!( + maud_move!( main { div .flox-playground { div .cell { @@ -291,8 +288,10 @@ where } (article(title, parsed, sack, outline, bibliography)) } - script type="module" { (Raw("import 'editor';")) } ), String::from("Flox"), + Some(&["editor".into()]) ) + .render() + .into() } diff --git a/src/html/post.rs b/src/html/post.rs index 538d729..c06b109 100644 --- a/src/html/post.rs +++ b/src/html/post.rs @@ -12,6 +12,7 @@ pub(crate) struct Post { #[serde(with = "super::isodate")] pub(crate) date: DateTime, pub(crate) desc: Option, + pub(crate) scripts: Option>, } impl Content for Post { @@ -49,7 +50,7 @@ impl Content for Post { } pub fn post<'s, 'p, 'html>( - metadata: &'p Post, + meta: &'p Post, parsed: &'p str, sack: &'s Sack, outline: Outline, @@ -61,11 +62,11 @@ where { let main = maud_move!( main { - (article(&metadata.title, parsed, sack, outline, bibliography)) + (article(&meta.title, parsed, sack, outline, bibliography)) } ); - crate::html::page(sack, main, metadata.title.clone()) + crate::html::page(sack, main, meta.title.clone(), meta.scripts.as_deref()) } pub fn article<'p, 's, 'html>( @@ -102,10 +103,8 @@ where } @if let Some(bib) = bibliography.0 { - (crate::html::misc::show_bibliography(bib)) + (crate::html::misc::emit_bibliography(bib)) } - - script type="module" {(Raw(r#"import "lambda";"#))} } } ) diff --git a/src/html/slideshow.rs b/src/html/slideshow.rs index f2821c1..8c0318e 100644 --- a/src/html/slideshow.rs +++ b/src/html/slideshow.rs @@ -77,13 +77,10 @@ pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String { } } - script type="module" { - (Raw("import 'reveal'; import 'search';")) - } - style { (Raw(CSS)) } ), fm.title.clone(), + Some(&["reveal".into()]) ) .render() .into() diff --git a/src/html/wiki.rs b/src/html/wiki.rs index 190c35e..aea78ef 100644 --- a/src/html/wiki.rs +++ b/src/html/wiki.rs @@ -75,13 +75,13 @@ fn wiki( } @if let Some(bib) = bibliography.0 { - (crate::html::misc::show_bibliography(bib)) + (crate::html::misc::emit_bibliography(bib)) } } } ); - crate::html::page(sack, main, matter.title.to_owned()) + crate::html::page(sack, main, matter.title.to_owned(), None) .render() .into() } diff --git a/src/main.rs b/src/main.rs index 8e68c73..12c6599 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ fn main() { "map/index.html".into(), ) .add_virtual( - |sack| crate::html::search(sack).render().to_owned().into(), + |sack| crate::html::search(sack), "search/index.html".into(), ) .add_virtual( diff --git a/styles/components/_bibliography.scss b/styles/components/_bibliography.scss index 798dc76..7a662e7 100644 --- a/styles/components/_bibliography.scss +++ b/styles/components/_bibliography.scss @@ -1,9 +1,11 @@ .bibliography { - li { - padding-left: 0.7em; + margin-top: 1em; - &::marker { - content: '[' counter(list-item) ']'; - } - } + li { + padding-left: 0.7em; + + &::marker { + content: "[" counter(list-item) "]"; + } + } }