Store the title in BlogPostPage.
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user