1
Fork 0
bauke-xyz/source/main.rs

50 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-13 23:50:38 +00:00
use std::{
fs,
path::{Path, PathBuf},
};
2021-11-26 13:08:13 +00:00
2021-12-13 23:50:38 +00:00
use color_eyre::{install, Result};
2021-11-26 13:08:13 +00:00
2021-12-13 23:50:38 +00:00
mod copy;
2023-01-09 14:43:05 +00:00
mod minify;
2021-12-13 23:50:38 +00:00
mod scss;
2021-11-26 13:08:13 +00:00
mod templates;
2023-01-07 13:57:19 +00:00
mod video;
2021-11-26 13:08:13 +00:00
2021-12-13 23:50:38 +00:00
fn main() -> Result<()> {
install()?;
2021-11-26 13:08:13 +00:00
let build_dir = PathBuf::from("target");
2021-12-13 23:50:38 +00:00
let public_dir = PathBuf::from("public");
let source_dir = PathBuf::from("source");
2021-11-26 13:08:13 +00:00
2021-12-13 23:50:38 +00:00
build_userstyles(&build_dir)?;
templates::Index::write(&public_dir)?;
scss::Scss::write(&public_dir, &source_dir)?;
copy::Copy::write(&build_dir, &public_dir, &source_dir)?;
2023-01-07 13:57:19 +00:00
video::write_all(&public_dir)?;
2021-12-13 23:50:38 +00:00
Ok(())
}
fn build_userstyles(build_dir: &Path) -> Result<()> {
2021-11-26 13:08:13 +00:00
for target in userstyles::ALL_USERSTYLES {
let style = userstyles::Userstyle::load(target)?;
let style_name = style.metadata.name.to_lowercase().replace(" ", "-");
2021-08-26 15:52:13 +00:00
2021-11-26 13:08:13 +00:00
let style_dir = build_dir.join("userstyles");
fs::create_dir_all(&style_dir)?;
2021-08-26 15:52:13 +00:00
2021-11-26 13:08:13 +00:00
let style_file = style_dir.join(format!("{}.user.css", style_name));
let formatted = style.format();
fs::write(style_file, formatted)?;
2021-08-26 15:52:13 +00:00
2021-11-26 13:08:13 +00:00
if let Some(image) = style.image {
let image_file = style_dir.join(format!("{}.png", style_name));
fs::write(image_file, image)?;
}
2021-08-26 15:52:13 +00:00
}
2021-11-26 13:08:13 +00:00
Ok(())
2021-08-26 15:52:13 +00:00
}