Compare commits

...

2 commits

Author SHA1 Message Date
Maciej Jur f97ec9e036
refactor 2024-09-16 00:15:24 +02:00
Maciej Jur b0b0d9d5df
refactor 2024-09-15 17:09:22 +02:00
4 changed files with 155 additions and 80 deletions

55
Cargo.lock generated
View file

@ -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"

View file

@ -1,9 +1,8 @@
use std::collections::HashMap;
use hauchiwa::Sack;
use camino::Utf8Path;
use hauchiwa::{Link, LinkDate, Sack};
use hypertext::{html_elements, maud, maud_move, GlobalAttributes, Raw, Renderable};
use crate::text::md::parse;
use crate::{html::Post, text::md::parse};
const INTRO: &str = r#"
##
@ -43,9 +42,20 @@ fn photo() -> impl Renderable {
fn latest(sack: &Sack) -> impl Renderable {
let links = {
let mut links = sack.get_links("**");
links.sort_by(|a, b| b.date.cmp(&a.date));
links
let mut list = sack
.get_meta::<Post>("**")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect::<Vec<_>>();
list.sort_by(|a, b| b.date.cmp(&a.date));
list
};
maud_move!(
@ -81,5 +91,8 @@ pub(crate) fn home(sack: &Sack, main: &str) -> String {
}
);
crate::html::page(sack, main, "Home".into(), None).unwrap().render().into()
crate::html::page(sack, main, "Home".into(), None)
.unwrap()
.render()
.into()
}

View file

@ -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<Utc>,
pub(crate) desc: Option<String>,
}
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<Linkable> {
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,

View file

@ -2,9 +2,10 @@ mod html;
mod text;
mod ts;
use camino::Utf8Path;
use clap::{Parser, ValueEnum};
use hauchiwa::{Loader, Processor, Website};
use html::{Flox, Post, Slideshow, Wiki};
use hauchiwa::{Collection, Link, LinkDate, Processor, Website};
use html::{Post, Slideshow, Wiki};
use hypertext::Renderable;
#[derive(Parser, Debug, Clone)]
@ -22,47 +23,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::<Post>("content", "about.md", ["md"].into(), processor_post.clone()),
Loader::glob_with::<Post>(
Collection::glob_with::<Post>(
"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::<Post>(
"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::<Slideshow>(
Collection::glob_with::<Slideshow>(
"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::<Wiki>(
"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::<Post>(
"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::<Wiki>("content", "wiki/**/*", ["md"].into(), processor_wiki),
Loader::glob_with::<Flox>("content", "projects/flox.md", ["md"].into(), processor_flox),
])
.js("search", "./js/search/dist/search.js")
.js("photos", "./js/vanilla/photos.js")
@ -78,21 +90,57 @@ fn main() {
|sack| {
crate::html::to_list(
sack,
sack.get_links("projects/**/*.html"),
sack.get_meta::<Post>("projects/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Projects".into(),
)
},
"projects/index.html".into(),
)
.add_virtual(
|sack| crate::html::to_list(sack, sack.get_links("posts/**/*.html"), "Posts".into()),
|sack| {
crate::html::to_list(
sack,
sack.get_meta::<Post>("posts/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Posts".into(),
)
},
"posts/index.html".into(),
)
.add_virtual(
|sack| {
crate::html::to_list(
sack,
sack.get_links("slides/**/*.html"),
sack.get_meta::<Slideshow>("slides/**/*.html")
.into_iter()
.map(|(path, meta)| LinkDate {
link: Link {
path: Utf8Path::new("/").join(path),
name: meta.title.clone(),
desc: meta.desc.clone(),
},
date: meta.date,
})
.collect(),
"Slideshows".into(),
)
},