Chunking the blog posts for the stream.
This commit is contained in:
@@ -87,19 +87,26 @@ impl BlogPost {
|
||||
/// all the pages under the blog post looking for any page that
|
||||
/// contains a date export setting. It will return the first date
|
||||
/// found.
|
||||
pub(crate) fn get_date(&self) -> Result<(), CustomError> {
|
||||
if let Some(index_page) = self.get_index_page()? {
|
||||
println!("{:?}", index_page);
|
||||
pub(crate) fn get_date(&self) -> Option<&str> {
|
||||
let index_page_date = self
|
||||
.get_index_page()
|
||||
.map(|index_page| index_page.date.as_ref().map(String::as_str))
|
||||
.flatten();
|
||||
if index_page_date.is_some() {
|
||||
return index_page_date;
|
||||
}
|
||||
Ok(())
|
||||
|
||||
self.pages
|
||||
.iter()
|
||||
.filter_map(|page| page.date.as_ref().map(String::as_str))
|
||||
.next()
|
||||
}
|
||||
|
||||
/// Get the blog post page for index.org
|
||||
fn get_index_page(&self) -> Result<Option<&BlogPostPage>, CustomError> {
|
||||
Ok(self
|
||||
.pages
|
||||
fn get_index_page(&self) -> Option<&BlogPostPage> {
|
||||
self.pages
|
||||
.iter()
|
||||
.find(|page| page.path == Path::new("index.org")))
|
||||
.find(|page| page.path == Path::new("index.org"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ pub(crate) struct BlogPostPage {
|
||||
|
||||
pub(crate) title: Option<String>,
|
||||
|
||||
pub(crate) date: Option<String>,
|
||||
|
||||
pub(crate) children: Vec<IDocumentElement>,
|
||||
|
||||
pub(crate) footnotes: Vec<IRealFootnoteDefinition>,
|
||||
@@ -60,6 +62,7 @@ impl BlogPostPage {
|
||||
Ok(BlogPostPage {
|
||||
path,
|
||||
title: get_title(&document),
|
||||
date: get_date(&document),
|
||||
children,
|
||||
footnotes,
|
||||
})
|
||||
@@ -85,3 +88,14 @@ fn get_title(document: &organic::types::Document<'_>) -> Option<String> {
|
||||
.last()
|
||||
.map(|kw| kw.value.to_owned())
|
||||
}
|
||||
|
||||
fn get_date(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("date") => Some(kw),
|
||||
_ => None,
|
||||
})
|
||||
.last()
|
||||
.map(|kw| kw.value.to_owned())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user