From b0b0d9d5df8aec24b5d8b4bd4d32816caf8541bf Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Sun, 15 Sep 2024 17:09:22 +0200 Subject: [PATCH] refactor --- Cargo.lock | 55 +++++++++++++++++++++++++++++++---- src/html/mod.rs | 31 +------------------- src/main.rs | 77 ++++++++++++++++++++++++++++--------------------- 3 files changed, 94 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61cc921..c57cea1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,6 +545,15 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "file-id" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6584280525fb2059cba3db2c04abf947a1a29a45ddae89f3870f8281704fafc9" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "filetime" version = "0.2.23" @@ -553,7 +562,7 @@ checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.4.1", "windows-sys 0.52.0", ] @@ -734,7 +743,7 @@ dependencies = [ "hayagriva", "image", "notify", - "notify-debouncer-mini", + "notify-debouncer-full", "rayon", "serde", "serde_json", @@ -1119,14 +1128,16 @@ dependencies = [ ] [[package]] -name = "notify-debouncer-mini" -version = "0.4.1" +name = "notify-debouncer-full" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43" +checksum = "49f5dab59c348b9b50cf7f261960a20e389feb2713636399cd9082cd4b536154" dependencies = [ - "crossbeam-channel", + "file-id", "log", "notify", + "parking_lot", + "walkdir", ] [[package]] @@ -1150,6 +1161,29 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.5.4", + "smallvec", + "windows-targets 0.52.4", +] + [[package]] name = "paste" version = "1.0.14" @@ -1383,6 +1417,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags 2.5.0", +] + [[package]] name = "regex" version = "1.10.6" diff --git a/src/html/mod.rs b/src/html/mod.rs index e0ffa19..721b343 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -212,26 +212,8 @@ pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String { .into() } -/// Represents a simple post. -#[derive(Deserialize, Debug, Clone)] -pub(crate) struct Flox { - pub(crate) title: String, - #[serde(with = "isodate")] - pub(crate) date: DateTime, - pub(crate) desc: Option, -} - -pub 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 as_html( - meta: &Flox, + meta: &Post, parsed: &str, sack: &Sack, outline: Outline, @@ -240,17 +222,6 @@ pub fn as_html( flox(&meta.title, parsed, sack, outline, bibliography) } -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>( title: &str, parsed: &str, diff --git a/src/main.rs b/src/main.rs index 492ac14..44b9081 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ mod text; mod ts; use clap::{Parser, ValueEnum}; -use hauchiwa::{Loader, Processor, Website}; -use html::{Flox, Post, Slideshow, Wiki}; +use hauchiwa::{Collection, Processor, Website}; +use html::{Post, Slideshow, Wiki}; use hypertext::Renderable; #[derive(Parser, Debug, Clone)] @@ -22,47 +22,58 @@ 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() .add_loaders(vec![ - Loader::glob_with::("content", "about.md", ["md"].into(), processor_post.clone()), - Loader::glob_with::( + Collection::glob_with::( + "content", + "about.md", + ["md"].into(), + Processor { + read_content: crate::html::post::parse_content, + to_html: crate::html::post::as_html, + to_link: crate::html::post::as_link, + }, + ), + Collection::glob_with::( "content", "posts/**/*", ["md", "mdx"].into(), - processor_post.clone(), + Processor { + read_content: crate::html::post::parse_content, + to_html: crate::html::post::as_html, + to_link: crate::html::post::as_link, + }, ), - Loader::glob_with::( + Collection::glob_with::( "content", "slides/**/*", ["md", "lhs"].into(), - processor_slideshow, + Processor { + read_content: crate::html::slideshow::parse_content, + to_html: crate::html::slideshow::as_html, + to_link: crate::html::slideshow::as_link, + }, + ), + Collection::glob_with::( + "content", + "wiki/**/*", + ["md"].into(), + Processor { + read_content: crate::html::wiki::parse_content, + to_html: crate::html::wiki::as_html, + to_link: crate::html::wiki::as_link, + }, + ), + Collection::glob_with::( + "content", + "projects/flox.md", + ["md"].into(), + Processor { + read_content: crate::html::post::parse_content, + to_html: crate::html::as_html, + to_link: crate::html::post::as_link, + }, ), - 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")