Writing the stylesheets to the output folder.

This commit is contained in:
Tom Alexander 2023-12-17 13:46:47 -05:00
parent 20c55f0708
commit 884215a7e1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 32 additions and 5 deletions

View File

@ -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(())
}
}

View File

@ -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(())
}

View File

@ -22,8 +22,13 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
let output_directory = output_directory.as_ref();
let output_file = output_file.as_ref();
let css_files = vec![
get_web_path(config, output_directory, output_file, "reset.css")?,
get_web_path(config, output_directory, output_file, "main.css")?,
get_web_path(
config,
output_directory,
output_file,
"stylesheet/reset.css",
)?,
get_web_path(config, output_directory, output_file, "stylesheet/main.css")?,
];
let js_files = vec![get_web_path(
config,