refactor: Simplify Site::write
This commit is contained in:
parent
98b744faa7
commit
96df281a20
54
src/site.rs
54
src/site.rs
|
@ -144,37 +144,33 @@ impl Site {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
debug!(?styles_dir, "Creating styles directory");
|
debug!(?styles_dir, "Creating styles directory");
|
||||||
|
let style_sheets: BTreeMap<&'static str, &'static [u8]> = [
|
||||||
|
(
|
||||||
|
"default.css",
|
||||||
|
include_bytes!("../assets/css/default.css").as_ref(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"index.css",
|
||||||
|
include_bytes!("../assets/css/index.css").as_ref(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"post.css",
|
||||||
|
include_bytes!("../assets/css/post.css").as_ref(),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.collect();
|
||||||
create_dir_all(&styles_dir).context(CreateDirectorySnafu { path: &styles_dir })?;
|
create_dir_all(&styles_dir).context(CreateDirectorySnafu { path: &styles_dir })?;
|
||||||
// Copy over the built in styles
|
// Copy over the built in styles
|
||||||
// default
|
for (style_name, style) in style_sheets {
|
||||||
let default_path = styles_dir.join("default.css");
|
let path = styles_dir.join(style_name);
|
||||||
debug!(?default_path, "Copying over default.css");
|
debug!(?path, "Copying over {style_name}");
|
||||||
let mut default = File::create(&default_path).context(WriteConfigSnafu {
|
let mut sheet = File::create(&path).context(WriteConfigSnafu { path: &path })?;
|
||||||
path: &default_path,
|
sheet
|
||||||
})?;
|
.write_all(style)
|
||||||
default
|
.context(WriteConfigSnafu { path: &path })?;
|
||||||
.write_all(include_bytes!("../assets/css/default.css"))
|
self.styles.insert(PathBuf::from(style_name));
|
||||||
.context(WriteConfigSnafu {
|
}
|
||||||
path: &default_path,
|
|
||||||
})?;
|
|
||||||
self.styles.insert(PathBuf::from("default.css"));
|
|
||||||
// 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 })?;
|
|
||||||
self.styles.insert(PathBuf::from("index.css"));
|
|
||||||
// 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 })?;
|
|
||||||
self.styles.insert(PathBuf::from("post.css"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue