Loading stylesheets from the default environment.
This commit is contained in:
parent
9e3d72972c
commit
20c55f0708
@ -1,4 +1,5 @@
|
||||
mod render;
|
||||
mod runner;
|
||||
mod stylesheet;
|
||||
|
||||
pub(crate) use runner::build_site;
|
||||
|
@ -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>(
|
||||
|
@ -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)
|
||||
}
|
||||
|
15
src/command/build/stylesheet.rs
Normal file
15
src/command/build/stylesheet.rs
Normal file
@ -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<Stylesheet, CustomError> {
|
||||
Ok(Stylesheet { path, contents })
|
||||
}
|
||||
}
|
@ -21,12 +21,10 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
|
||||
) -> Result<RenderBlogPostPage, CustomError> {
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user