Merge branch 'css'
This commit is contained in:
commit
1ff41940a5
0
default_environment/stylesheet/main.css
Normal file
0
default_environment/stylesheet/main.css
Normal file
48
default_environment/stylesheet/reset.css
Normal file
48
default_environment/stylesheet/reset.css
Normal file
@ -0,0 +1,48 @@
|
||||
/* http://meyerweb.com/eric/tools/css/reset/
|
||||
v2.0 | 20110126
|
||||
License: none (public domain)
|
||||
*/
|
||||
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
a, abbr, acronym, address, big, cite, code,
|
||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||
small, strike, strong, sub, sup, tt, var,
|
||||
b, u, i, center,
|
||||
dl, dt, dd, ol, ul, li,
|
||||
fieldset, form, label, legend,
|
||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||
article, aside, canvas, details, embed,
|
||||
figure, figcaption, footer, header, hgroup,
|
||||
menu, nav, output, ruby, section, summary,
|
||||
time, mark, audio, video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
article, aside, details, figcaption, figure,
|
||||
footer, header, hgroup, menu, nav, section {
|
||||
display: block;
|
||||
}
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
ol, ul {
|
||||
list-style: none;
|
||||
}
|
||||
blockquote, q {
|
||||
quotes: none;
|
||||
}
|
||||
blockquote:before, blockquote:after,
|
||||
q:before, q:after {
|
||||
content: '';
|
||||
content: none;
|
||||
}
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod render;
|
||||
mod runner;
|
||||
mod stylesheet;
|
||||
|
||||
pub(crate) use runner::build_site;
|
||||
|
@ -11,23 +11,29 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn render_blog_posts(&self, config: &Config) -> Result<(), CustomError> {
|
||||
let mut renderer_integration = DusterRenderer::new();
|
||||
|
||||
@ -82,6 +88,22 @@ impl SiteRenderer {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
fn build_name_contents_pairs<'a>(
|
||||
|
@ -1,16 +1,29 @@
|
||||
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 renderer = SiteRenderer::new(get_output_directory(&config).await?, blog_posts);
|
||||
let stylesheets = load_stylesheets().await?;
|
||||
let renderer = SiteRenderer::new(
|
||||
get_output_directory(&config).await?,
|
||||
blog_posts,
|
||||
stylesheets,
|
||||
);
|
||||
renderer.render_blog_posts(&config).await?;
|
||||
renderer.render_stylesheets().await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -58,3 +71,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,15 @@ 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(
|
||||
let css_files = vec![
|
||||
get_web_path(
|
||||
config,
|
||||
output_directory,
|
||||
output_file,
|
||||
"main.css",
|
||||
)?];
|
||||
"stylesheet/reset.css",
|
||||
)?,
|
||||
get_web_path(config, output_directory, output_file, "stylesheet/main.css")?,
|
||||
];
|
||||
let js_files = vec![get_web_path(
|
||||
config,
|
||||
output_directory,
|
||||
|
Loading…
x
Reference in New Issue
Block a user