From fc817f1375aef84427670b5d5f66cb8eca0f592d Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Fri, 17 Mar 2023 19:30:47 -0400 Subject: [PATCH] feat: Add pre-baked css files for init --- assets/css/default.css | 0 assets/css/index.css | 0 assets/css/post.css | 0 src/site.rs | 46 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 assets/css/default.css create mode 100644 assets/css/index.css create mode 100644 assets/css/post.css diff --git a/assets/css/default.css b/assets/css/default.css new file mode 100644 index 0000000..e69de29 diff --git a/assets/css/index.css b/assets/css/index.css new file mode 100644 index 0000000..e69de29 diff --git a/assets/css/post.css b/assets/css/post.css new file mode 100644 index 0000000..e69de29 diff --git a/src/site.rs b/src/site.rs index f43feed..f532cac 100644 --- a/src/site.rs +++ b/src/site.rs @@ -102,6 +102,8 @@ pub struct Site { /// /// Path is relative to `statics` directory pub statics: Vec, + /// Stylesheets + pub styles: Vec, } 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(()) } }