diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..6a34f55 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +tab_spaces = 4 +hard_tabs = true diff --git a/src/html/mod.rs b/src/html/mod.rs index c706598..e0ffa19 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -1,18 +1,17 @@ +mod head; mod home; mod isodate; mod list; mod misc; -mod post; -mod slideshow; -mod special; -mod wiki; -mod head; +pub mod post; +pub mod slideshow; +pub mod wiki; use std::collections::HashMap; use camino::{Utf8Path, Utf8PathBuf}; use chrono::{DateTime, Datelike, Utc}; -use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack}; +use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack}; use hayagriva::Library; use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable}; @@ -119,7 +118,7 @@ where 's: 'html, 'p: 'html, { - let head = head::render_head(sack, title, &[], js)?; + let head = head::render_head(sack, title, &[], js)?; Ok(maud_move!( (Raw("")) @@ -133,7 +132,6 @@ where )) } - fn full<'s, 'p, 'html>( sack: &'s Sack, main: impl Renderable + 'p, @@ -143,10 +141,7 @@ where 's: 'html, 'p: 'html, { - let main = maud_move!( - (navbar()) - (main) - ); + let main = maud_move!((navbar())(main)); bare(sack, main, title, None) } @@ -161,11 +156,7 @@ where 's: 'html, 'p: 'html, { - let main = maud_move!( - (navbar()) - (main) - (footer(sack)) - ); + let main = maud_move!((navbar())(main)(footer(sack))); bare(sack, main, title, js) } @@ -214,14 +205,13 @@ pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String { main #app {} ), String::from("Search"), - Some(&["search".into()]) + Some(&["search".into()]), ) - .unwrap() - .render() - .into() + .unwrap() + .render() + .into() } - /// Represents a simple post. #[derive(Deserialize, Debug, Clone)] pub(crate) struct Flox { @@ -231,36 +221,34 @@ pub(crate) struct Flox { pub(crate) desc: Option, } -impl Content for Flox { - fn parse_content( - content: &str, - sack: &Sack, - path: &Utf8Path, - library: Option<&Library>, - ) -> (String, Outline, Bibliography) { - crate::text::md::parse(content, sack, path, library) - } +pub fn parse_content( + content: &str, + sack: &Sack, + path: &Utf8Path, + library: Option<&Library>, +) -> (String, Outline, Bibliography) { + crate::text::md::parse(content, sack, path, library) +} - fn as_html( - &self, - parsed: &str, - sack: &Sack, - outline: Outline, - bibliography: Bibliography, - ) -> String { - flox(&self.title, parsed, sack, outline, bibliography) - } +pub fn as_html( + meta: &Flox, + parsed: &str, + sack: &Sack, + outline: Outline, + bibliography: Bibliography, +) -> String { + flox(&meta.title, parsed, sack, outline, bibliography) +} - fn as_link(&self, path: Utf8PathBuf) -> Option { - Some(Linkable::Date(LinkDate { - link: Link { - path, - name: self.title.to_owned(), - desc: self.desc.to_owned(), - }, - date: self.date.to_owned(), - })) - } +pub fn as_link(meta: &Flox, path: Utf8PathBuf) -> Option { + Some(Linkable::Date(LinkDate { + link: Link { + path, + name: meta.title.to_owned(), + desc: meta.desc.to_owned(), + }, + date: meta.date.to_owned(), + })) } pub(crate) fn flox<'p, 's, 'html>( @@ -274,28 +262,28 @@ pub(crate) fn flox<'p, 's, 'html>( sack, maud_move!( main { - div .flox-playground { - div .cell { - header { - h2 { "Flox" } - } - div .editor { - div #editor {} - button #run .run { "Run!" } - } - } - div .cell { - h2 { "Output" } - pre #output {} - } - } - (article(title, parsed, sack, outline, bibliography)) - } + div .flox-playground { + div .cell { + header { + h2 { "Flox" } + } + div .editor { + div #editor {} + button #run .run { "Run!" } + } + } + div .cell { + h2 { "Output" } + pre #output {} + } + } + (article(title, parsed, sack, outline, bibliography)) + } ), String::from("Flox"), - Some(&["editor".into()]) + Some(&["editor".into()]), ) - .unwrap() - .render() - .into() + .unwrap() + .render() + .into() } diff --git a/src/html/post.rs b/src/html/post.rs index 47587ec..5bc72cd 100644 --- a/src/html/post.rs +++ b/src/html/post.rs @@ -1,53 +1,51 @@ use camino::{Utf8Path, Utf8PathBuf}; use chrono::{DateTime, Utc}; -use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack}; +use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack}; use hayagriva::Library; use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable}; use serde::Deserialize; /// Represents a simple post. #[derive(Deserialize, Debug, Clone)] -pub(crate) struct Post { - pub(crate) title: String, +pub struct Post { + pub title: String, #[serde(with = "super::isodate")] - pub(crate) date: DateTime, - pub(crate) desc: Option, - pub(crate) scripts: Option>, + pub date: DateTime, + pub desc: Option, + pub scripts: Option>, } -impl Content for Post { - fn parse_content( - content: &str, - sack: &Sack, - path: &Utf8Path, - library: Option<&Library>, - ) -> (String, Outline, Bibliography) { - crate::text::md::parse(content, sack, path, library) - } +pub fn parse_content( + content: &str, + sack: &Sack, + path: &Utf8Path, + library: Option<&Library>, +) -> (String, Outline, Bibliography) { + crate::text::md::parse(content, sack, path, library) +} - fn as_html( - &self, - parsed: &str, - sack: &Sack, - outline: Outline, - bibliography: Bibliography, - ) -> String { - post(self, parsed, sack, outline, bibliography) - .unwrap() - .render() - .into() - } +pub fn as_html( + meta: &Post, + parsed: &str, + sack: &Sack, + outline: Outline, + bibliography: Bibliography, +) -> String { + post(meta, parsed, sack, outline, bibliography) + .unwrap() + .render() + .into() +} - fn as_link(&self, path: Utf8PathBuf) -> Option { - Some(Linkable::Date(LinkDate { - link: Link { - path, - name: self.title.to_owned(), - desc: self.desc.to_owned(), - }, - date: self.date.to_owned(), - })) - } +pub fn as_link(meta: &Post, path: Utf8PathBuf) -> Option { + Some(Linkable::Date(LinkDate { + link: Link { + path, + name: meta.title.to_owned(), + desc: meta.desc.to_owned(), + }, + date: meta.date.to_owned(), + })) } pub fn post<'s, 'p, 'html>( diff --git a/src/html/slideshow.rs b/src/html/slideshow.rs index fb8b64e..49af0be 100644 --- a/src/html/slideshow.rs +++ b/src/html/slideshow.rs @@ -1,6 +1,6 @@ use camino::{Utf8Path, Utf8PathBuf}; use chrono::{DateTime, Utc}; -use hauchiwa::{Bibliography, Content, Link, LinkDate, Linkable, Outline, Sack}; +use hauchiwa::{Bibliography, Link, LinkDate, Linkable, Outline, Sack}; use hayagriva::Library; use hypertext::{html_elements, maud, GlobalAttributes, Raw, Renderable}; use serde::Deserialize; @@ -16,73 +16,77 @@ const CSS: &str = r#" /// Represents a slideshow #[derive(Deserialize, Debug, Clone)] pub(crate) struct Slideshow { - pub title: String, - #[serde(with = "super::isodate")] - pub date: DateTime, - pub desc: Option, + pub title: String, + #[serde(with = "super::isodate")] + pub date: DateTime, + pub desc: Option, } -impl Content for Slideshow { - fn parse_content( - content: &str, - sack: &Sack, - path: &Utf8Path, - library: Option<&Library>, - ) -> (String, Outline, Bibliography) { - let parsed = content - .split("\n-----\n") - .map(|chunk| { - chunk - .split("\n---\n") - .map(|slide| crate::text::md::parse(&slide, sack, path, library).0) - .collect::>() - }) - .map(|stack| match stack.len() > 1 { - true => format!( - "
{}
", - stack - .into_iter() - .map(|slide| format!("
{slide}
")) - .collect::() - ), - false => format!("
{}
", stack[0]), - }) - .collect::(); - (parsed, Outline(vec![]), Bibliography(None)) - } +pub fn parse_content( + content: &str, + sack: &Sack, + path: &Utf8Path, + library: Option<&Library>, +) -> (String, Outline, Bibliography) { + let parsed = content + .split("\n-----\n") + .map(|chunk| { + chunk + .split("\n---\n") + .map(|slide| crate::text::md::parse(&slide, sack, path, library).0) + .collect::>() + }) + .map(|stack| match stack.len() > 1 { + true => format!( + "
{}
", + stack + .into_iter() + .map(|slide| format!("
{slide}
")) + .collect::() + ), + false => format!("
{}
", stack[0]), + }) + .collect::(); + (parsed, Outline(vec![]), Bibliography(None)) +} - fn as_html(&self, parsed: &str, sack: &Sack, _: Outline, _: Bibliography) -> String { - show(self, sack, parsed) - } +pub fn as_html( + slides: &Slideshow, + parsed: &str, + sack: &Sack, + _: Outline, + _: Bibliography, +) -> String { + show(slides, sack, parsed) +} - fn as_link(&self, path: Utf8PathBuf) -> Option { - Some(Linkable::Date(LinkDate { - link: Link { - path, - name: self.title.to_owned(), - desc: self.desc.to_owned(), - }, - date: self.date.to_owned(), - })) - } +pub fn as_link(slides: &Slideshow, path: Utf8PathBuf) -> Option { + Some(Linkable::Date(LinkDate { + link: Link { + path, + name: slides.title.to_owned(), + desc: slides.desc.to_owned(), + }, + date: slides.date.to_owned(), + })) } pub fn show(fm: &Slideshow, sack: &Sack, slides: &str) -> String { - crate::html::bare( - sack, - maud!( - div .reveal { - div .slides { - (Raw(slides)) - } - } + crate::html::bare( + sack, + maud!( + div .reveal { + div .slides { + (Raw(slides)) + } + } - style { (Raw(CSS)) } - ), - fm.title.clone(), - Some(&["reveal".into()]) - ) - .unwrap() - .render() - .into() + style { (Raw(CSS)) } + ), + fm.title.clone(), + Some(&["reveal".into()]), + ) + .unwrap() + .render() + .into() } diff --git a/src/html/special.rs b/src/html/special.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/html/wiki.rs b/src/html/wiki.rs index f2594a7..6435ca5 100644 --- a/src/html/wiki.rs +++ b/src/html/wiki.rs @@ -1,5 +1,5 @@ use camino::{Utf8Path, Utf8PathBuf}; -use hauchiwa::{Bibliography, Content, Link, Linkable, Outline, Sack}; +use hauchiwa::{Bibliography, Link, Linkable, Outline, Sack}; use hayagriva::Library; use hypertext::{html_elements, maud_move, GlobalAttributes, Raw, Renderable}; use serde::Deserialize; @@ -10,33 +10,31 @@ pub struct Wiki { pub title: String, } -impl Content for Wiki { - fn parse_content( - content: &str, - sack: &Sack, - path: &Utf8Path, - library: Option<&Library>, - ) -> (String, Outline, Bibliography) { - crate::text::md::parse(content, sack, path, library) - } +pub fn parse_content( + content: &str, + sack: &Sack, + path: &Utf8Path, + library: Option<&Library>, +) -> (String, Outline, Bibliography) { + crate::text::md::parse(content, sack, path, library) +} - fn as_html( - &self, - parsed: &str, - sack: &Sack, - outline: Outline, - bibliography: Bibliography, - ) -> String { - wiki(self, parsed, sack, outline, bibliography) - } +pub fn as_html( + meta: &Wiki, + parsed: &str, + sack: &Sack, + outline: Outline, + bibliography: Bibliography, +) -> String { + wiki(meta, parsed, sack, outline, bibliography) +} - fn as_link(&self, path: Utf8PathBuf) -> Option { - Some(Linkable::Link(Link { - path, - name: self.title.to_owned(), - desc: None, - })) - } +pub fn as_link(meta: &Wiki, path: Utf8PathBuf) -> Option { + Some(Linkable::Link(Link { + path, + name: meta.title.to_owned(), + desc: None, + })) } fn wiki( @@ -82,7 +80,7 @@ fn wiki( ); crate::html::page(sack, main, matter.title.to_owned(), None) - .unwrap() + .unwrap() .render() .into() } diff --git a/src/main.rs b/src/main.rs index 144a6bd..492ac14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod text; mod ts; use clap::{Parser, ValueEnum}; -use hauchiwa::Website; +use hauchiwa::{Loader, Processor, Website}; use html::{Flox, Post, Slideshow, Wiki}; use hypertext::Renderable; @@ -22,12 +22,48 @@ enum Mode { fn main() { let args = Args::parse(); + let processor_post = Processor { + read_content: crate::html::post::parse_content, + to_html: crate::html::post::as_html, + to_link: crate::html::post::as_link, + }; + + let processor_slideshow = Processor { + read_content: crate::html::slideshow::parse_content, + to_html: crate::html::slideshow::as_html, + to_link: crate::html::slideshow::as_link, + }; + + let processor_wiki = Processor { + read_content: crate::html::wiki::parse_content, + to_html: crate::html::wiki::as_html, + to_link: crate::html::wiki::as_link, + }; + + let processor_flox = Processor { + read_content: crate::html::parse_content, + to_html: crate::html::as_html, + to_link: crate::html::as_link, + }; + let website = Website::design() - .content::("content/about.md", ["md"].into()) - .content::("content/posts/**/*", ["md", "mdx"].into()) - .content::("content/slides/**/*", ["md", "lhs"].into()) - .content::("content/wiki/**/*", ["md"].into()) - .content::("content/projects/flox.md", ["md"].into()) + .add_loaders(vec![ + Loader::glob_with::("content", "about.md", ["md"].into(), processor_post.clone()), + Loader::glob_with::( + "content", + "posts/**/*", + ["md", "mdx"].into(), + processor_post.clone(), + ), + Loader::glob_with::( + "content", + "slides/**/*", + ["md", "lhs"].into(), + processor_slideshow, + ), + Loader::glob_with::("content", "wiki/**/*", ["md"].into(), processor_wiki), + Loader::glob_with::("content", "projects/flox.md", ["md"].into(), processor_flox), + ]) .js("search", "./js/search/dist/search.js") .js("photos", "./js/vanilla/photos.js") .js("reveal", "./js/vanilla/reveal.js") @@ -37,12 +73,15 @@ fn main() { |sack| crate::html::map(sack).unwrap().render().to_owned().into(), "map/index.html".into(), ) + .add_virtual(|sack| crate::html::search(sack), "search/index.html".into()) .add_virtual( - |sack| crate::html::search(sack), - "search/index.html".into(), - ) - .add_virtual( - |sack| crate::html::to_list(sack, sack.get_links("projects/**/*.html"), "Projects".into()), + |sack| { + crate::html::to_list( + sack, + sack.get_links("projects/**/*.html"), + "Projects".into(), + ) + }, "projects/index.html".into(), ) .add_virtual( diff --git a/styles/_flox.scss b/styles/_flox.scss index 4180c66..0c2bd6c 100644 --- a/styles/_flox.scss +++ b/styles/_flox.scss @@ -1,43 +1,43 @@ .flox-playground { - display: grid; - grid-template-columns: 1fr 1fr; - grid-template-rows: max(24rem, 0.5vh); - gap: 1em; - margin-block: 0.5em; - padding: 1em; + display: grid; + grid-template-columns: 1fr 1fr; + grid-template-rows: max(24rem, 0.5vh); + gap: 1em; + margin-block: 0.5em; + padding: 1em; - .editor, - #output { - height: calc(100% - 4em); - overflow-y: auto; - border: 1px dashed black; - border-radius: 0.5em; - background-color: white; - } + .editor, + #output { + height: calc(100% - 4em); + overflow-y: auto; + border: 1px dashed black; + border-radius: 0.5em; + background-color: white; + } - .editor { - position: relative; + .editor { + position: relative; - #run { - position: absolute; - right: 0.5em; - bottom: 0.5em; - padding: 0.25em 0.5em; - } - } + #run { + position: absolute; + right: 0.5em; + bottom: 0.5em; + padding: 0.25em 0.5em; + } + } - #output { - padding: 1em; - } + #output { + padding: 1em; + } } .flox-eval { - border-radius: 0.5em; - border: 1px solid black; - overflow: auto; + border-radius: 0.5em; + border: 1px solid black; + overflow: auto; - > .output { - padding: 0.25em 0.5em; - border-top: 1px solid black; - } + > .output { + padding: 0.25em 0.5em; + border-top: 1px solid black; + } }