Writing the stylesheets to the output folder.
This commit is contained in:
@@ -11,21 +11,26 @@ use crate::intermediate::BlogPost;
|
||||
use crate::render::DusterRenderer;
|
||||
use crate::render::RendererIntegration;
|
||||
|
||||
use super::stylesheet::Stylesheet;
|
||||
|
||||
static MAIN_TEMPLATES: Dir = include_dir!("$CARGO_MANIFEST_DIR/default_environment/templates/html");
|
||||
|
||||
pub(crate) struct SiteRenderer {
|
||||
output_directory: PathBuf,
|
||||
blog_posts: Vec<BlogPost>,
|
||||
stylesheets: Vec<Stylesheet>,
|
||||
}
|
||||
|
||||
impl SiteRenderer {
|
||||
pub(crate) fn new<P: Into<PathBuf>>(
|
||||
output_directory: P,
|
||||
blog_posts: Vec<BlogPost>,
|
||||
stylesheets: Vec<Stylesheet>,
|
||||
) -> SiteRenderer {
|
||||
SiteRenderer {
|
||||
output_directory: output_directory.into(),
|
||||
blog_posts,
|
||||
stylesheets,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +89,20 @@ impl SiteRenderer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn copy_stylesheets(&self, config: &Config) -> Result<(), CustomError> {
|
||||
todo!()
|
||||
pub(crate) async fn render_stylesheets(&self) -> Result<(), CustomError> {
|
||||
let stylesheet_output_directory = self.output_directory.join("stylesheet");
|
||||
if !stylesheet_output_directory.exists() {
|
||||
tokio::fs::create_dir(&stylesheet_output_directory).await?;
|
||||
}
|
||||
for stylesheet in &self.stylesheets {
|
||||
let file_output_path = stylesheet_output_directory.join(&stylesheet.path);
|
||||
let parent_directory = file_output_path
|
||||
.parent()
|
||||
.ok_or("Output file should have a containing directory.")?;
|
||||
tokio::fs::create_dir_all(parent_directory).await?;
|
||||
tokio::fs::write(file_output_path, stylesheet.contents.as_bytes()).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,13 @@ 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?;
|
||||
let stylesheets = load_stylesheets().await?;
|
||||
let renderer = SiteRenderer::new(get_output_directory(&config).await?, blog_posts);
|
||||
let renderer = SiteRenderer::new(
|
||||
get_output_directory(&config).await?,
|
||||
blog_posts,
|
||||
stylesheets,
|
||||
);
|
||||
renderer.render_blog_posts(&config).await?;
|
||||
renderer.render_stylesheets().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user