refactor
This commit is contained in:
parent
a0df7388d8
commit
b0b0d9d5df
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -545,6 +545,15 @@ dependencies = [
|
||||||
"simd-adler32",
|
"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]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.23"
|
version = "0.2.23"
|
||||||
|
@ -553,7 +562,7 @@ checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall 0.4.1",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -734,7 +743,7 @@ dependencies = [
|
||||||
"hayagriva",
|
"hayagriva",
|
||||||
"image",
|
"image",
|
||||||
"notify",
|
"notify",
|
||||||
"notify-debouncer-mini",
|
"notify-debouncer-full",
|
||||||
"rayon",
|
"rayon",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -1119,14 +1128,16 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "notify-debouncer-mini"
|
name = "notify-debouncer-full"
|
||||||
version = "0.4.1"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5d40b221972a1fc5ef4d858a2f671fb34c75983eb385463dff3780eeff6a9d43"
|
checksum = "49f5dab59c348b9b50cf7f261960a20e389feb2713636399cd9082cd4b536154"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossbeam-channel",
|
"file-id",
|
||||||
"log",
|
"log",
|
||||||
"notify",
|
"notify",
|
||||||
|
"parking_lot",
|
||||||
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1150,6 +1161,29 @@ version = "1.19.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
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]]
|
[[package]]
|
||||||
name = "paste"
|
name = "paste"
|
||||||
version = "1.0.14"
|
version = "1.0.14"
|
||||||
|
@ -1383,6 +1417,15 @@ dependencies = [
|
||||||
"bitflags 1.3.2",
|
"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]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.10.6"
|
version = "1.10.6"
|
||||||
|
|
|
@ -212,26 +212,8 @@ pub(crate) fn search<'s, 'html>(sack: &'s Sack) -> String {
|
||||||
.into()
|
.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(
|
pub fn as_html(
|
||||||
meta: &Flox,
|
meta: &Post,
|
||||||
parsed: &str,
|
parsed: &str,
|
||||||
sack: &Sack,
|
sack: &Sack,
|
||||||
outline: Outline,
|
outline: Outline,
|
||||||
|
@ -240,17 +222,6 @@ pub fn as_html(
|
||||||
flox(&meta.title, parsed, sack, outline, bibliography)
|
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>(
|
pub(crate) fn flox<'p, 's, 'html>(
|
||||||
title: &str,
|
title: &str,
|
||||||
parsed: &str,
|
parsed: &str,
|
||||||
|
|
75
src/main.rs
75
src/main.rs
|
@ -3,8 +3,8 @@ mod text;
|
||||||
mod ts;
|
mod ts;
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use hauchiwa::{Loader, Processor, Website};
|
use hauchiwa::{Collection, Processor, Website};
|
||||||
use html::{Flox, Post, Slideshow, Wiki};
|
use html::{Post, Slideshow, Wiki};
|
||||||
use hypertext::Renderable;
|
use hypertext::Renderable;
|
||||||
|
|
||||||
#[derive(Parser, Debug, Clone)]
|
#[derive(Parser, Debug, Clone)]
|
||||||
|
@ -22,47 +22,58 @@ enum Mode {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let processor_post = Processor {
|
let website = Website::design()
|
||||||
|
.add_loaders(vec![
|
||||||
|
Collection::glob_with::<Post>(
|
||||||
|
"content",
|
||||||
|
"about.md",
|
||||||
|
["md"].into(),
|
||||||
|
Processor {
|
||||||
read_content: crate::html::post::parse_content,
|
read_content: crate::html::post::parse_content,
|
||||||
to_html: crate::html::post::as_html,
|
to_html: crate::html::post::as_html,
|
||||||
to_link: crate::html::post::as_link,
|
to_link: crate::html::post::as_link,
|
||||||
};
|
},
|
||||||
|
),
|
||||||
let processor_slideshow = Processor {
|
Collection::glob_with::<Post>(
|
||||||
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>(
|
|
||||||
"content",
|
"content",
|
||||||
"posts/**/*",
|
"posts/**/*",
|
||||||
["md", "mdx"].into(),
|
["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",
|
"content",
|
||||||
"slides/**/*",
|
"slides/**/*",
|
||||||
["md", "lhs"].into(),
|
["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("search", "./js/search/dist/search.js")
|
||||||
.js("photos", "./js/vanilla/photos.js")
|
.js("photos", "./js/vanilla/photos.js")
|
||||||
|
|
Loading…
Reference in a new issue