2024-06-30 22:47:28 +03:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
2025-06-25 13:44:08 +03:00
|
|
|
use std::{fs, path::PathBuf};
|
|
|
|
|
|
2025-06-24 19:56:47 +03:00
|
|
|
use askama::Template;
|
2025-06-25 13:44:08 +03:00
|
|
|
use blake3::{Hash, Hasher};
|
2024-06-30 22:47:28 +03:00
|
|
|
use tracing_subscriber::EnvFilter;
|
|
|
|
|
|
2025-06-24 19:56:47 +03:00
|
|
|
mod common;
|
|
|
|
|
|
2025-01-31 14:50:31 +02:00
|
|
|
#[cfg(feature = "bbs")]
|
2024-09-28 16:32:23 +03:00
|
|
|
mod bbs;
|
2025-01-31 14:50:31 +02:00
|
|
|
|
|
|
|
|
#[cfg(feature = "ddd")]
|
2024-09-29 02:15:18 +03:00
|
|
|
mod ddd;
|
2025-01-31 14:50:31 +02:00
|
|
|
|
2025-06-25 02:15:27 +03:00
|
|
|
#[cfg(feature = "kh1")]
|
|
|
|
|
mod kh1;
|
|
|
|
|
|
2025-02-08 13:35:55 +02:00
|
|
|
#[cfg(feature = "kh2")]
|
|
|
|
|
mod kh2;
|
|
|
|
|
|
2025-01-31 14:50:31 +02:00
|
|
|
#[cfg(feature = "kh3")]
|
2025-01-27 14:55:10 +02:00
|
|
|
mod kh3;
|
2024-06-30 22:47:28 +03:00
|
|
|
|
2024-07-01 18:24:37 +03:00
|
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
2025-06-28 00:47:43 +03:00
|
|
|
pub const ASSETS_FOLDER_PATH: &str = "./public/assets";
|
2024-06-30 22:47:28 +03:00
|
|
|
|
2025-06-25 13:44:08 +03:00
|
|
|
pub trait RuntimeModule {
|
|
|
|
|
fn start_module();
|
|
|
|
|
|
|
|
|
|
fn get_js_hash() -> String;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 14:50:31 +02:00
|
|
|
#[derive(Template)]
|
|
|
|
|
#[template(path = "pages/index.html")]
|
|
|
|
|
struct IndexTemplate {}
|
|
|
|
|
|
2024-06-30 22:47:28 +03:00
|
|
|
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();
|
|
|
|
|
|
2025-01-31 14:50:31 +02:00
|
|
|
tracing::info!("Generating the main menu template");
|
|
|
|
|
let template = IndexTemplate {};
|
|
|
|
|
|
|
|
|
|
std::fs::write("./out/index.html", template.render().unwrap()).unwrap();
|
2025-02-10 00:47:36 +02:00
|
|
|
std::process::Command::new("cp")
|
|
|
|
|
.args(["-r", "./assets", "./out"])
|
|
|
|
|
.output()
|
|
|
|
|
.unwrap();
|
2025-01-31 14:50:31 +02:00
|
|
|
|
|
|
|
|
#[cfg(feature = "bbs")]
|
2025-06-25 13:44:08 +03:00
|
|
|
start_module::<bbs::Module>();
|
2025-01-31 14:50:31 +02:00
|
|
|
|
|
|
|
|
#[cfg(feature = "ddd")]
|
2025-06-25 13:44:08 +03:00
|
|
|
start_module::<ddd::Module>();
|
2025-01-31 14:50:31 +02:00
|
|
|
|
2025-06-25 02:15:27 +03:00
|
|
|
#[cfg(feature = "kh1")]
|
2025-06-25 13:44:08 +03:00
|
|
|
start_module::<kh1::Module>();
|
2025-06-25 02:15:27 +03:00
|
|
|
|
2025-02-08 13:35:55 +02:00
|
|
|
#[cfg(feature = "kh2")]
|
2025-06-25 13:44:08 +03:00
|
|
|
start_module::<kh2::Module>();
|
2025-02-08 13:35:55 +02:00
|
|
|
|
2025-01-31 14:50:31 +02:00
|
|
|
#[cfg(feature = "kh3")]
|
2025-06-25 13:44:08 +03:00
|
|
|
start_module::<kh3::Module>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn start_module<M: RuntimeModule>() {
|
|
|
|
|
M::start_module();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn create_hashes(module: &str) -> Hash {
|
2025-06-25 14:44:55 +03:00
|
|
|
let mut hasher = Hasher::new();
|
2025-06-25 13:44:08 +03:00
|
|
|
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);
|
|
|
|
|
}
|
2024-06-30 22:47:28 +03:00
|
|
|
}
|
2025-01-31 15:06:04 +02:00
|
|
|
|
|
|
|
|
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(())
|
|
|
|
|
}
|