diff --git a/Cargo.toml b/Cargo.toml index ec3f35a..9a2d4c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +default-run = "jana_sessions_webpage" + [dependencies] chrono = { version = "0.4", features = ["serde"] } leptos = { version = "0.7", features = ["csr"] } console_error_panic_hook = "0.1.7" serde = { version = "1.0", features = ["derive"] } -gloo-timers = { version = "0.3", features = ["futures"] } +serde_json = "1.0" +config = {path = "config"} \ No newline at end of file diff --git a/Trunk.toml b/Trunk.toml index 4c2681b..7076f3b 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -1,4 +1,9 @@ [build] filehash = false dist = "target/dist" -public_url = "." \ No newline at end of file +public_url = "." + +[[hooks]] +stage = "post_build" +command = "cargo" +command_arguments = ["run", "--bin", "create_static_configs"] \ No newline at end of file diff --git a/config/Cargo.toml b/config/Cargo.toml new file mode 100644 index 0000000..03f2d02 --- /dev/null +++ b/config/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "config" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0", features = ["derive"] } diff --git a/config/src/lib.rs b/config/src/lib.rs new file mode 100644 index 0000000..9f1b239 --- /dev/null +++ b/config/src/lib.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SessionConfig { + pub motd: String, +} + +impl Default for SessionConfig { + fn default() -> Self { + Self { + motd: "Proben Dienstags um 18:30 Uhr und Sonntags um 10:00 Uhr".to_string(), + } + } +} \ No newline at end of file diff --git a/index.html b/index.html index 105d24a..25b06b2 100644 --- a/index.html +++ b/index.html @@ -2,12 +2,12 @@ Band Sessions - + diff --git a/session_config.json b/session_config.json deleted file mode 100644 index a5d454c..0000000 --- a/session_config.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "motd": "Proben Sonntags um 10:00 Uhr und Dienstags um 18:30 Uhr" -} \ No newline at end of file diff --git a/src/bin/create_static_configs.rs b/src/bin/create_static_configs.rs new file mode 100644 index 0000000..ac9bad3 --- /dev/null +++ b/src/bin/create_static_configs.rs @@ -0,0 +1,21 @@ +use config::SessionConfig; +use serde::Serialize; +use std::env; +use std::fs::File; +use std::path::Path; + +fn main() { + let out_dir = env::var_os("TRUNK_STAGING_DIR").expect("Not called during trunk build lifecycle"); + create_default_config::("session_config", &out_dir); +} + +fn create_default_config(name: &str, out_dir: P) +where + T: Default + Serialize, + P: AsRef, +{ + let out_path = out_dir.as_ref().join(format!("{name}.json")); + let out_file = File::create(&out_path).unwrap(); + let default_config = T::default(); + serde_json::to_writer_pretty(out_file, &default_config).unwrap(); +} diff --git a/src/webpage.rs b/src/webpage.rs index c7f479f..9cea227 100644 --- a/src/webpage.rs +++ b/src/webpage.rs @@ -1,11 +1,6 @@ +use config::SessionConfig; use leptos::prelude::*; use leptos::server_fn::request::browser::Request; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SessionConfig { - pub motd: String, -} #[component] pub fn App() -> impl IntoView { @@ -17,7 +12,7 @@ pub fn App() -> impl IntoView { .as_deref() .cloned() .map(|config| match config { - Ok(config) => view! { }.into_any(), + Ok(config) => view! { }.into_any(), Err(e) => { view! {

{format!("Failed to load Sessions config: {e}")}

}.into_any() }