Store the title in BlogPostPage.
This commit is contained in:
parent
e543a5db74
commit
dc233d26b1
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -336,8 +336,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "organic"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a3f0f8a2a6d31c3cac7ebf543d8cb2e8f648300462fc2f6b1a09cac10daf0387"
|
||||
dependencies = [
|
||||
"nom 7.1.3",
|
||||
"walkdir",
|
||||
|
@ -9,7 +9,9 @@ edition = "2021"
|
||||
clap = { version = "4.4.6", default-features = false, features = ["std", "color", "help", "derive"] }
|
||||
duster = { git = "https://code.fizz.buzz/talexander/duster.git", branch = "master" }
|
||||
include_dir = "0.7.3"
|
||||
organic = "0.1.12"
|
||||
# TODO: This is temporary to work on the latest organic code. Eventually switch back to using the published crate.
|
||||
organic = { path = "../organic" }
|
||||
# organic = "0.1.12"
|
||||
serde = { version = "1.0.189", default-features = false, features = ["std", "derive"] }
|
||||
serde_json = "1.0.107"
|
||||
tokio = { version = "1.30.0", default-features = false, features = ["rt", "rt-multi-thread", "fs", "io-util"] }
|
||||
|
@ -7,7 +7,7 @@ pub(crate) struct BlogPostPage {
|
||||
/// Relative path from the root of the blog post.
|
||||
path: PathBuf,
|
||||
|
||||
title: String,
|
||||
title: Option<String>,
|
||||
}
|
||||
|
||||
impl BlogPostPage {
|
||||
@ -18,7 +18,20 @@ impl BlogPostPage {
|
||||
let path = path.into();
|
||||
Ok(BlogPostPage {
|
||||
path,
|
||||
title: "".to_owned(),
|
||||
title: get_title(&document),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn get_title(document: &organic::types::Document<'_>) -> Option<String> {
|
||||
organic::types::AstNode::from(document)
|
||||
.iter_all_ast_nodes()
|
||||
.filter_map(|node| match node {
|
||||
organic::types::AstNode::Keyword(kw) if kw.key.eq_ignore_ascii_case("title") => {
|
||||
Some(kw)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.last()
|
||||
.map(|kw| kw.value.to_owned())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user