Store the title in BlogPostPage.

This commit is contained in:
Tom Alexander
2023-10-23 18:39:54 -04:00
parent e543a5db74
commit dc233d26b1
3 changed files with 18 additions and 5 deletions

View File

@@ -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())
}