From d06a629affdf89bd12235a68e23808f9a0139324 Mon Sep 17 00:00:00 2001 From: Wynd Date: Fri, 31 Jan 2025 15:06:04 +0200 Subject: [PATCH] Bit of a reorganization for output and template files --- src/bbs.rs | 10 ++++++---- src/ddd.rs | 8 +++++--- src/kh3.rs | 8 +++++--- src/main.rs | 6 ++++++ .../pages/{bbs-commands.html => bbs/melding.html} | 0 .../pages/{ddd-abilities.html => ddd/boards.html} | 0 templates/pages/index.html | 6 +++--- .../pages/{kh3-recipes.html => kh3/food-sim.html} | 0 8 files changed, 25 insertions(+), 13 deletions(-) rename templates/pages/{bbs-commands.html => bbs/melding.html} (100%) rename templates/pages/{ddd-abilities.html => ddd/boards.html} (100%) rename templates/pages/{kh3-recipes.html => kh3/food-sim.html} (100%) diff --git a/src/bbs.rs b/src/bbs.rs index 4d26132..5ab2b79 100644 --- a/src/bbs.rs +++ b/src/bbs.rs @@ -4,6 +4,8 @@ use itertools::Itertools; use rinja::Template; use serde::Deserialize; +use crate::create_file; + #[derive(Debug, Deserialize, PartialEq, Eq)] enum Character { #[serde(alias = "A")] @@ -119,7 +121,7 @@ struct Finisher { } #[derive(Template)] -#[template(path = "pages/bbs-commands.html")] +#[template(path = "pages/bbs/melding.html")] struct CommandsTemplate { pub commands: Vec, pub crystals: Vec, @@ -157,8 +159,8 @@ pub fn init() { } } - tracing::info!("Generating the BBS commands table template"); - let template = CommandsTemplate { commands, crystals }; + tracing::info!("Generating the BBS melding table template"); + let melding_template = CommandsTemplate { commands, crystals }; - std::fs::write("./out/bbs-commands.html", template.render().unwrap()).unwrap(); + create_file("./out/bbs", "melding", melding_template.render().unwrap()).unwrap(); } diff --git a/src/ddd.rs b/src/ddd.rs index 4cafd7f..679212f 100644 --- a/src/ddd.rs +++ b/src/ddd.rs @@ -4,6 +4,8 @@ use itertools::Itertools; use rinja::Template; use serde::{Deserialize, Deserializer}; +use crate::create_file; + #[derive(Debug, Deserialize, PartialEq, Eq)] struct Board { order: u32, @@ -348,7 +350,7 @@ impl Display for Interaction { } #[derive(Template)] -#[template(path = "pages/ddd-abilities.html")] +#[template(path = "pages/ddd/boards.html")] struct AbilitiesTemplate { pub boards: Vec, } @@ -385,7 +387,7 @@ pub fn init() { boards.sort_by(|a, b| a.order.cmp(&b.order)); tracing::info!("Generating the DDD ability boards template"); - let template = AbilitiesTemplate { boards }; + let boards_template = AbilitiesTemplate { boards }; - std::fs::write("./out/ddd-abilities.html", template.render().unwrap()).unwrap(); + create_file("./out/ddd", "boards", boards_template.render().unwrap()).unwrap(); } diff --git a/src/kh3.rs b/src/kh3.rs index 183c754..66a1c8f 100644 --- a/src/kh3.rs +++ b/src/kh3.rs @@ -3,6 +3,8 @@ use std::fmt::Display; use rinja::Template; use serde::Deserialize; +use crate::create_file; + #[derive(Debug, Deserialize, PartialEq, Eq)] struct Recipes { starters: Vec, @@ -55,7 +57,7 @@ impl Display for FoodStats { } #[derive(Template)] -#[template(path = "pages/kh3-recipes.html")] +#[template(path = "pages/kh3/food-sim.html")] struct RecipesTemplate { pub recipes: Recipes, } @@ -68,7 +70,7 @@ pub fn init() { let recipes = toml::from_str::(&recipes_str).unwrap(); tracing::info!("Generating the KH3 recipes template"); - let template = RecipesTemplate { recipes }; + let food_template = RecipesTemplate { recipes }; - std::fs::write("./out/kh3-recipes.html", template.render().unwrap()).unwrap(); + create_file("./out/kh3", "food-sim", food_template.render().unwrap()).unwrap(); } diff --git a/src/main.rs b/src/main.rs index cebcf50..195e917 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,3 +39,9 @@ fn main() { #[cfg(feature = "kh3")] kh3::init(); } + +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(()) +} diff --git a/templates/pages/bbs-commands.html b/templates/pages/bbs/melding.html similarity index 100% rename from templates/pages/bbs-commands.html rename to templates/pages/bbs/melding.html diff --git a/templates/pages/ddd-abilities.html b/templates/pages/ddd/boards.html similarity index 100% rename from templates/pages/ddd-abilities.html rename to templates/pages/ddd/boards.html diff --git a/templates/pages/index.html b/templates/pages/index.html index d9dff1d..a4b3aa2 100644 --- a/templates/pages/index.html +++ b/templates/pages/index.html @@ -9,21 +9,21 @@ {% if cfg!(feature = "bbs") %}

Kingdom Hearts Birth by Sleep

{% endif %} {% if cfg!(feature = "ddd") %}

Kingdom Hearts Dream Drop Distance

{% endif %} {% if cfg!(feature = "kh3") %}

Kingdom Hearts III

{% endif %} {% endblock %} diff --git a/templates/pages/kh3-recipes.html b/templates/pages/kh3/food-sim.html similarity index 100% rename from templates/pages/kh3-recipes.html rename to templates/pages/kh3/food-sim.html