Invoke dust to render the stream pages.

At this point the render_blog_stream function is done, but RenderBlogStream::new needs to be implemented to actually generate the render context. The body of this function should be similar to convert_blog_post_page_to_render_context.
This commit is contained in:
Tom Alexander 2023-12-17 17:26:15 -05:00
parent 2ba4a5e3d7
commit cbe2010407
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 29 additions and 10 deletions

View File

@ -5,6 +5,7 @@ use include_dir::include_dir;
use include_dir::Dir;
use crate::config::Config;
use crate::context::RenderBlogStream;
use crate::error::CustomError;
use crate::intermediate::convert_blog_post_page_to_render_context;
use crate::intermediate::get_web_path;
@ -35,7 +36,7 @@ impl SiteRenderer {
}
}
pub(crate) async fn render_blog_posts(&self, config: &Config) -> Result<(), CustomError> {
fn init_renderer_integration(&self) -> Result<DusterRenderer<'_>, CustomError> {
let mut renderer_integration = DusterRenderer::new();
let sources: Vec<_> = MAIN_TEMPLATES
@ -63,6 +64,12 @@ impl SiteRenderer {
renderer_integration.load_template(name, contents)?;
}
Ok(renderer_integration)
}
pub(crate) async fn render_blog_posts(&self, config: &Config) -> Result<(), CustomError> {
let renderer_integration = self.init_renderer_integration()?;
for blog_post in &self.blog_posts {
for blog_post_page in &blog_post.pages {
let output_path = self
@ -91,15 +98,7 @@ impl SiteRenderer {
}
pub(crate) async fn render_blog_stream(&self, config: &Config) -> Result<(), CustomError> {
// TODO: Actually render a blog stream to index.html
// Steps: sort blog posts by date, newest first
//
// Steps: group blog posts based on # of posts per page
//
// Steps: for each group, create a RenderBlogStream
//
// Steps: pass each RenderBlogStream to dust as the context to render index.html and any additional stream pages.
let renderer_integration = self.init_renderer_integration()?;
// Sort blog posts by date, newest first.
let sorted_blog_posts = {
@ -158,6 +157,23 @@ impl SiteRenderer {
format!("stream/{}.html", page_num + 1),
)?)
};
let blog_stream = RenderBlogStream::new(
config,
self.output_directory.as_path(),
output_file.as_path(),
chunk,
older_link,
newer_link,
)?;
// Pass each RenderBlogStream to dust as the context to render index.html and any additional stream pages.
let rendered_output = renderer_integration.render(blog_stream)?;
let parent_directory = output_file
.parent()
.ok_or("Output file should have a containing directory.")?;
tokio::fs::create_dir_all(parent_directory).await?;
tokio::fs::write(output_file, rendered_output).await?;
}
Ok(())
}

View File

@ -28,6 +28,8 @@ impl RenderBlogStream {
output_directory: &Path,
output_file: &Path,
original: &[&BlogPost],
older_link: Option<String>,
newer_link: Option<String>,
) -> Result<RenderBlogStream, CustomError> {
todo!()
}

View File

@ -65,6 +65,7 @@ mod verbatim;
mod verse_block;
pub(crate) use blog_post_page::RenderBlogPostPage;
pub(crate) use blog_stream::RenderBlogStream;
pub(crate) use document_element::RenderDocumentElement;
pub(crate) use element::RenderElement;
pub(crate) use footnote_definition::RenderRealFootnoteDefinition;