Creating a SiteRenderer struct to handle the logic for invoking dust.
This commit is contained in:
parent
0b6900eeca
commit
5f34cb2dd5
@ -1,3 +1,4 @@
|
||||
mod render;
|
||||
mod runner;
|
||||
|
||||
pub(crate) use runner::build_site;
|
||||
|
21
src/command/build/render.rs
Normal file
21
src/command/build/render.rs
Normal 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(())
|
||||
}
|
||||
}
|
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user