38 lines
938 B
Rust
38 lines
938 B
Rust
use std::sync::OnceLock;
|
|
|
|
use askama::Template;
|
|
use blake3::Hash;
|
|
use food::Recipes;
|
|
|
|
use crate::{RuntimeModule, create_file, create_hashes};
|
|
|
|
mod food;
|
|
|
|
const RECIPES_PATH: &str = "./input/kh3/recipes.toml";
|
|
static JS_HASH: OnceLock<Hash> = OnceLock::new();
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "pages/kh3/food-sim.html")]
|
|
struct RecipesTemplate {
|
|
pub recipes: Recipes,
|
|
}
|
|
|
|
pub struct Module;
|
|
|
|
impl RuntimeModule for Module {
|
|
fn start_module() {
|
|
tracing::info!("Loading recipes data from {}", RECIPES_PATH);
|
|
let recipes_str = std::fs::read_to_string(RECIPES_PATH).unwrap();
|
|
let recipes = toml::from_str::<Recipes>(&recipes_str).unwrap();
|
|
|
|
tracing::info!("Generating the KH3 recipes template");
|
|
let food_template = RecipesTemplate { recipes };
|
|
|
|
create_file("./out/kh3", "food-sim", food_template.render().unwrap()).unwrap();
|
|
}
|
|
|
|
fn get_js_hash() -> String {
|
|
JS_HASH.get_or_init(|| create_hashes("kh3")).to_string()
|
|
}
|
|
}
|