#![allow(dead_code)] use std::{fs, path::PathBuf}; use askama::Template; use blake3::{Hash, Hasher}; use tracing_subscriber::EnvFilter; mod common; #[cfg(feature = "bbs")] mod bbs; #[cfg(feature = "ddd")] mod ddd; #[cfg(feature = "kh1")] mod kh1; #[cfg(feature = "kh2")] mod kh2; #[cfg(feature = "kh3")] mod kh3; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const ASSETS_FOLDER_PATH: &str = "./public/assets"; pub trait RuntimeModule { fn start_module(); fn get_js_hash() -> String; } #[derive(Template)] #[template(path = "pages/index.html")] struct IndexTemplate {} fn main() { // Initialize tracing tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) .event_format(tracing_subscriber::fmt::format().with_source_location(true)) .init(); tracing::info!("Generating the main menu template"); let template = IndexTemplate {}; std::fs::write("./out/index.html", template.render().unwrap()).unwrap(); std::process::Command::new("cp") .args(["-r", "./assets", "./out"]) .output() .unwrap(); #[cfg(feature = "bbs")] start_module::(); #[cfg(feature = "ddd")] start_module::(); #[cfg(feature = "kh1")] start_module::(); #[cfg(feature = "kh2")] start_module::(); #[cfg(feature = "kh3")] start_module::(); } fn start_module() { M::start_module(); } fn create_hashes(module: &str) -> Hash { let mut hasher = Hasher::new(); hash_file(format!("./public/scripts/{module}.js").into(), &mut hasher); hash_files_in_dir("./public/scripts/modules/common".into(), &mut hasher); hash_files_in_dir( format!("./public/scripts/modules/{module}").into(), &mut hasher, ); hasher.finalize() } fn hash_files_in_dir(path: PathBuf, hasher: &mut Hasher) { if let Ok(paths) = fs::read_dir(path) { for path in paths.flatten() { let path = path.path(); if path.metadata().is_ok_and(|p| p.is_dir()) { hash_files_in_dir(path, hasher); continue; } hash_file(path, hasher); } } } fn hash_file(path: PathBuf, hasher: &mut Hasher) { if let Ok(file) = fs::read(path) { hasher.update(&file); } } fn create_file(dir: &str, file: &str, buf: String) -> std::io::Result<()> { std::fs::create_dir_all(dir)?; std::fs::write(format!("{}/{}.html", dir, file), buf)?; Ok(()) }