From 6511115b95dfa165fb5d76a9a0c8d12be2dcbb0a Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 19 Dec 2023 10:59:34 -0500 Subject: [PATCH] Implement a flawed version of RenderBlogStreamEntry::new. There are some shortcomings in this implementation listed in the comments, but this is the general structure. --- src/context/blog_stream.rs | 29 ++++++++++++++++++++++++++++- src/intermediate/blog_post.rs | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/context/blog_stream.rs b/src/context/blog_stream.rs index 31c78c9..5c2c7a9 100644 --- a/src/context/blog_stream.rs +++ b/src/context/blog_stream.rs @@ -93,6 +93,33 @@ impl RenderBlogStreamEntry { output_file: &Path, original: &BlogPost, ) -> Result { - todo!() + // TODO: This link is probably wrong. + let link_to_blog_post = get_web_path( + config, + output_directory, + output_file, + output_file.strip_prefix(output_directory)?, + )?; + + // TODO: Should I guess an index page instead of erroring out? + let index_page = original + .get_index_page() + .ok_or_else(|| format!("Blog post {} needs an index page.", original.id))?; + + let title = index_page.title.clone(); + + // TODO: Handle footnotes. + let children = index_page + .children + .iter() + .map(|child| RenderDocumentElement::new(config, output_directory, output_file, child)) + .collect::, _>>()?; + + Ok(RenderBlogStreamEntry { + title, + self_link: Some(link_to_blog_post), + children, + footnotes: Vec::new(), + }) } } diff --git a/src/intermediate/blog_post.rs b/src/intermediate/blog_post.rs index 865528b..52c38ef 100644 --- a/src/intermediate/blog_post.rs +++ b/src/intermediate/blog_post.rs @@ -103,7 +103,7 @@ impl BlogPost { } /// Get the blog post page for index.org - fn get_index_page(&self) -> Option<&BlogPostPage> { + pub(crate) fn get_index_page(&self) -> Option<&BlogPostPage> { self.pages .iter() .find(|page| page.path == Path::new("index.org"))