From 30bfe4dc801fdfd3ab8d7a5e36bba67eee70d33b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 7 Oct 2025 17:32:43 +0200 Subject: Split book exporting to own crate; move locale tool to server dir --- server/book-export/src/main.rs | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 server/book-export/src/main.rs (limited to 'server/book-export/src/main.rs') diff --git a/server/book-export/src/main.rs b/server/book-export/src/main.rs new file mode 100644 index 00000000..b57aa04f --- /dev/null +++ b/server/book-export/src/main.rs @@ -0,0 +1,60 @@ +/* + Hurry Curry! - a game about cooking + Copyright (C) 2025 Hurry Curry! Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +*/ +pub mod book_html; +pub mod diagram_svg; + +use crate::book_html::render_html_book; +use anyhow::Result; +use clap::{Parser, ValueEnum}; +use hurrycurry_data::{book::book, index::DataIndex}; +use hurrycurry_locale::FALLBACK_LOCALE; + +#[derive(Parser)] +struct Args { + #[arg(short, long)] + format: ExportFormat, + #[arg(short, long, default_value = "5star")] + map: String, +} + +#[derive(ValueEnum, Clone, Copy)] +enum ExportFormat { + Json, + Html, +} + +fn main() -> Result<()> { + env_logger::init_from_env("LOG"); + let args = Args::parse(); + + let mut index = DataIndex::default(); + index.reload()?; + let (data, serverdata) = index.generate(&args.map)?; + + let book = book(&data, &serverdata)?; + + match args.format { + ExportFormat::Json => { + println!("{}", serde_json::to_string(&book).unwrap()) + } + ExportFormat::Html => { + println!("{}", render_html_book(&data, &book, &FALLBACK_LOCALE)); + } + } + Ok(()) +} -- cgit v1.3