Creating a SiteRenderer struct to handle the logic for invoking dust.

This commit is contained in:
Tom Alexander 2023-10-22 16:10:41 -04:00
parent 0b6900eeca
commit 5f34cb2dd5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 28 additions and 7 deletions

View File

@ -1,3 +1,4 @@
mod render;
mod runner;
pub(crate) use runner::build_site;

View File

@ -0,0 +1,21 @@
use std::path::PathBuf;
use crate::blog_post::convert_blog_post_to_render_context;
use crate::blog_post::BlogPost;
use crate::error::CustomError;
pub(crate) struct SiteRenderer {
pub(crate) output_directory: PathBuf,
pub(crate) blog_posts: Vec<BlogPost>,
}
impl SiteRenderer {
pub(crate) async fn render_blog_posts(&self) -> Result<(), CustomError> {
for blog_post in &self.blog_posts {
let render_context = convert_blog_post_to_render_context(blog_post);
println!("{}", serde_json::to_string(&render_context)?);
}
Ok(())
}
}

View File

@ -1,20 +1,19 @@
use std::path::PathBuf;
use crate::blog_post::convert_blog_post_to_render_context;
use crate::blog_post::BlogPost;
use crate::cli::parameters::BuildArgs;
use crate::command::build::render::SiteRenderer;
use crate::config::Config;
use crate::error::CustomError;
pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> {
let config = Config::load_from_file(args.config).await?;
let blog_posts = load_blog_posts(&config).await?;
println!("{:?}", blog_posts);
for blog_post in &blog_posts {
let render_context = convert_blog_post_to_render_context(blog_post);
println!("{}", serde_json::to_string(&render_context)?);
}
let renderer = SiteRenderer {
output_directory: get_output_directory(&config).await?,
blog_posts,
};
renderer.render_blog_posts().await?;
Ok(())
}