Loading stylesheets from the default environment.
This commit is contained in:
@@ -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<Vec<BlogPost>, CustomError>
|
||||
}
|
||||
Ok(blog_posts)
|
||||
}
|
||||
|
||||
async fn load_stylesheets() -> Result<Vec<Stylesheet>, 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user