Generate default configs
This commit is contained in:
parent
ce1eb3a0d4
commit
da9813a2cf
@ -5,9 +5,12 @@ edition = "2021"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
default-run = "jana_sessions_webpage"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
leptos = { version = "0.7", features = ["csr"] }
|
leptos = { version = "0.7", features = ["csr"] }
|
||||||
console_error_panic_hook = "0.1.7"
|
console_error_panic_hook = "0.1.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
gloo-timers = { version = "0.3", features = ["futures"] }
|
serde_json = "1.0"
|
||||||
|
config = {path = "config"}
|
||||||
@ -1,4 +1,9 @@
|
|||||||
[build]
|
[build]
|
||||||
filehash = false
|
filehash = false
|
||||||
dist = "target/dist"
|
dist = "target/dist"
|
||||||
public_url = "."
|
public_url = "."
|
||||||
|
|
||||||
|
[[hooks]]
|
||||||
|
stage = "post_build"
|
||||||
|
command = "cargo"
|
||||||
|
command_arguments = ["run", "--bin", "create_static_configs"]
|
||||||
7
config/Cargo.toml
Normal file
7
config/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "config"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
14
config/src/lib.rs
Normal file
14
config/src/lib.rs
Normal file
@ -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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,12 +2,12 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Band Sessions</title>
|
<title>Band Sessions</title>
|
||||||
<link data-trunk rel="copy-file" href="session_config.json"/>
|
|
||||||
<style>
|
<style>
|
||||||
.red {
|
.red {
|
||||||
color:red;
|
color:red;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<link data-trunk rel="rust" data-bin="jana_sessions_webpage" />
|
||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body></body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"motd": "Proben Sonntags um 10:00 Uhr und Dienstags um 18:30 Uhr"
|
|
||||||
}
|
|
||||||
21
src/bin/create_static_configs.rs
Normal file
21
src/bin/create_static_configs.rs
Normal file
@ -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::<SessionConfig, _>("session_config", &out_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_default_config<T, P>(name: &str, out_dir: P)
|
||||||
|
where
|
||||||
|
T: Default + Serialize,
|
||||||
|
P: AsRef<Path>,
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
@ -1,11 +1,6 @@
|
|||||||
|
use config::SessionConfig;
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos::server_fn::request::browser::Request;
|
use leptos::server_fn::request::browser::Request;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct SessionConfig {
|
|
||||||
pub motd: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
@ -17,7 +12,7 @@ pub fn App() -> impl IntoView {
|
|||||||
.as_deref()
|
.as_deref()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|config| match config {
|
.map(|config| match config {
|
||||||
Ok(config) => view! { <Sessions config></Sessions> }.into_any(),
|
Ok(config) => view! { <Sessions config /> }.into_any(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
view! { <p class="red">{format!("Failed to load Sessions config: {e}")}</p> }.into_any()
|
view! { <p class="red">{format!("Failed to load Sessions config: {e}")}</p> }.into_any()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user