diff --git a/Cargo.lock b/Cargo.lock index 8ce1ec8..44e485f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index cefc0b4..4026897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/blog_post/page.rs b/src/blog_post/page.rs index 21e7c3f..a0d94b7 100644 --- a/src/blog_post/page.rs +++ b/src/blog_post/page.rs @@ -7,7 +7,7 @@ pub(crate) struct BlogPostPage { /// Relative path from the root of the blog post. path: PathBuf, - title: String, + title: Option, } 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 { + 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()) +}