diff --git a/.gitignore b/.gitignore index 2c38871..099e1e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -Cargo.lock -/target -/dist \ No newline at end of file +**/Cargo.lock +**/target \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 9a2d4c6..8ae639d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,6 @@ 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"] } diff --git a/Trunk.toml b/Trunk.toml index 7076f3b..9648c93 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -6,4 +6,4 @@ public_url = "." [[hooks]] stage = "post_build" command = "cargo" -command_arguments = ["run", "--bin", "create_static_configs"] \ No newline at end of file +command_arguments = ["run", "--manifest-path", "config/Cargo.toml"] \ No newline at end of file diff --git a/config/Cargo.toml b/config/Cargo.toml index 03f2d02..2c4664b 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/config/src/lib.rs b/config/src/lib.rs index 9f1b239..bfcb4b0 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -3,12 +3,4 @@ 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/config/src/main.rs b/config/src/main.rs new file mode 100644 index 0000000..719383c --- /dev/null +++ b/config/src/main.rs @@ -0,0 +1,24 @@ +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").unwrap_or("target".into()); + + create_config("session_config", &out_dir, &SessionConfig { + motd: "Proben Dienstags um 18:30 Uhr und Sonntags um 10:00 Uhr".to_string(), + }) +} + +fn create_config(name: &str, out_dir: P, default_config: &T) + where + T: Serialize, + P: AsRef, +{ + //TODO return, if config already exists and is up to date + let out_path = out_dir.as_ref().join(format!("{name}.json")); + let out_file = File::create(&out_path).unwrap(); + serde_json::to_writer_pretty(out_file, default_config).unwrap(); +} \ No newline at end of file diff --git a/index.html b/index.html index 25b06b2..b31a2aa 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,6 @@ color:red; } - diff --git a/src/bin/create_static_configs.rs b/src/bin/create_static_configs.rs deleted file mode 100644 index ac9bad3..0000000 --- a/src/bin/create_static_configs.rs +++ /dev/null @@ -1,21 +0,0 @@ -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(); -}