diff --git a/src/command/build/mod.rs b/src/command/build/mod.rs index 8edcb15..b1b161e 100644 --- a/src/command/build/mod.rs +++ b/src/command/build/mod.rs @@ -1,4 +1,5 @@ mod render; mod runner; +mod stylesheet; pub(crate) use runner::build_site; diff --git a/src/command/build/render.rs b/src/command/build/render.rs index 853028a..501b4ab 100644 --- a/src/command/build/render.rs +++ b/src/command/build/render.rs @@ -28,6 +28,7 @@ impl SiteRenderer { blog_posts, } } + pub(crate) async fn render_blog_posts(&self, config: &Config) -> Result<(), CustomError> { let mut renderer_integration = DusterRenderer::new(); @@ -82,6 +83,10 @@ impl SiteRenderer { Ok(()) } + + pub(crate) async fn copy_stylesheets(&self, config: &Config) -> Result<(), CustomError> { + todo!() + } } fn build_name_contents_pairs<'a>( diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index 13dc846..4033d1d 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -1,14 +1,22 @@ +use std::ffi::OsStr; use std::path::PathBuf; +use super::stylesheet::Stylesheet; use crate::cli::parameters::BuildArgs; use crate::command::build::render::SiteRenderer; use crate::config::Config; use crate::error::CustomError; use crate::intermediate::BlogPost; +use include_dir::include_dir; +use include_dir::Dir; + +static DEFAULT_STYLESHEETS: Dir = + include_dir!("$CARGO_MANIFEST_DIR/default_environment/stylesheet"); 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); renderer.render_blog_posts(&config).await?; @@ -58,3 +66,18 @@ async fn load_blog_posts(config: &Config) -> Result, CustomError> } Ok(blog_posts) } + +async fn load_stylesheets() -> Result, CustomError> { + let sources: Vec<_> = DEFAULT_STYLESHEETS + .files() + .filter(|f| f.path().extension() == Some(OsStr::new("css"))) + .collect(); + let mut ret = Vec::with_capacity(sources.len()); + for entry in sources { + let path = entry.path().to_path_buf(); + let contents = String::from_utf8(entry.contents().to_vec())?; + let stylesheet = Stylesheet::new(path, contents).await?; + ret.push(stylesheet); + } + Ok(ret) +} diff --git a/src/command/build/stylesheet.rs b/src/command/build/stylesheet.rs new file mode 100644 index 0000000..1c2fab5 --- /dev/null +++ b/src/command/build/stylesheet.rs @@ -0,0 +1,15 @@ +use std::path::PathBuf; + +use crate::error::CustomError; + +#[derive(Debug)] +pub(crate) struct Stylesheet { + pub(crate) path: PathBuf, + pub(crate) contents: String, +} + +impl Stylesheet { + pub(crate) async fn new(path: PathBuf, contents: String) -> Result { + Ok(Stylesheet { path, contents }) + } +} diff --git a/src/intermediate/convert.rs b/src/intermediate/convert.rs index 6bdb654..d600b1e 100644 --- a/src/intermediate/convert.rs +++ b/src/intermediate/convert.rs @@ -21,12 +21,10 @@ pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef< ) -> Result { 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, - "main.css", - )?]; + let css_files = vec![ + get_web_path(config, output_directory, output_file, "reset.css")?, + get_web_path(config, output_directory, output_file, "main.css")?, + ]; let js_files = vec![get_web_path( config, output_directory,