feat: Add pre-baked css files for init

This commit is contained in:
Nathan McCarty 2023-03-17 19:30:47 -04:00
parent 534c04bd11
commit fc817f1375
Signed by: thatonelutenist
GPG Key ID: D70DA3DD4D1E9F96
4 changed files with 46 additions and 0 deletions

0
assets/css/default.css Normal file
View File

0
assets/css/index.css Normal file
View File

0
assets/css/post.css Normal file
View File

View File

@ -102,6 +102,8 @@ pub struct Site {
///
/// Path is relative to `statics` directory
pub statics: Vec<PathBuf>,
/// Stylesheets
pub styles: Vec<PathBuf>,
}
impl Default for Site {
@ -115,6 +117,7 @@ impl Default for Site {
pages,
posts,
statics: Vec::new(),
styles: Vec::new(),
}
}
}
@ -194,6 +197,49 @@ impl Site {
.context(WriteConfigSnafu {
path: &git_ignore_path,
})?;
// Write out the stylesheets
let styles_dir = site_dir.join("styles");
if styles_dir
.try_exists()
.context(ExistanceCheckSnafu { path: &styles_dir })?
{
debug!(?styles_dir, "Validating styles directory");
ensure!(
styles_dir.is_dir(),
NotADirectorySnafu { path: &styles_dir }
);
} else {
debug!(?styles_dir, "Creating styles directory");
create_dir_all(&styles_dir).context(CreateDirectorySnafu { path: &styles_dir })?;
// Copy over the built in styles
// default
let default_path = styles_dir.join("default.css");
debug!(?default_path, "Copying over default.css");
let mut default = File::create(&default_path).context(WriteConfigSnafu {
path: &default_path,
})?;
default
.write_all(include_bytes!("../assets/css/default.css"))
.context(WriteConfigSnafu {
path: &default_path,
})?;
// index
let index_path = styles_dir.join("index.css");
debug!(?index_path, "Copying over index.css");
let mut index =
File::create(&index_path).context(WriteConfigSnafu { path: &index_path })?;
index
.write_all(include_bytes!("../assets/css/index.css"))
.context(WriteConfigSnafu { path: &index_path })?;
// post
let post_path = styles_dir.join("post.css");
debug!(?post_path, "Copying over post.css");
let mut post =
File::create(&post_path).context(WriteConfigSnafu { path: &post_path })?;
post.write_all(include_bytes!("../assets/css/post.css"))
.context(WriteConfigSnafu { path: &post_path })?;
}
Ok(())
}
}