diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/components/editor/mod.rs | 0 | ||||
-rw-r--r-- | src/components/mod.rs | 2 | ||||
-rw-r--r-- | src/components/renderer/mod.rs | 0 | ||||
-rw-r--r-- | src/data/config.rs | 45 | ||||
-rw-r--r-- | src/data/mod.rs | 3 | ||||
-rw-r--r-- | src/data/pages.rs | 0 | ||||
-rw-r--r-- | src/data/users.rs | 0 | ||||
-rw-r--r-- | src/main.rs | 2 |
10 files changed, 56 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock index b441a79..0689de2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1863,8 +1863,10 @@ dependencies = [ "leptos_axum", "leptos_meta", "leptos_router", + "serde", "stylance", "tokio", + "toml", "wasm-bindgen", ] diff --git a/Cargo.toml b/Cargo.toml index 68a9c52..1086f32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,9 @@ leptos_axum = { version = "0.7.0", optional = true } leptos_meta = { version = "0.7.0" } tokio = { version = "1", features = ["rt-multi-thread", "signal"], optional = true } wasm-bindgen = { version = "=0.2.100", optional = true } +serde = { version = "^1.0.219", features = ["derive"] } stylance = "0.5.5" +toml = { version = "0.8.20", features = ["parse"] } [features] default = ["ssr"] diff --git a/src/components/editor/mod.rs b/src/components/editor/mod.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/components/editor/mod.rs diff --git a/src/components/mod.rs b/src/components/mod.rs index 62ca08a..2015a2e 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -1,4 +1,6 @@ +pub mod editor; pub mod layout; +pub mod renderer; pub mod app; diff --git a/src/components/renderer/mod.rs b/src/components/renderer/mod.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/components/renderer/mod.rs diff --git a/src/data/config.rs b/src/data/config.rs new file mode 100644 index 0000000..bce5c94 --- /dev/null +++ b/src/data/config.rs @@ -0,0 +1,45 @@ +use std::fs; +use std::path::{Path, PathBuf}; + +use serde::Deserialize; + +#[derive(Deserialize)] +struct ConfigFile { + site_title: Option<String>, + data_dir: Option<PathBuf>, + external_root: Option<String>, + listen_port: Option<u16>, + footer_copyright: Option<String>, +} + +pub struct Config { + site_title: String, + data_dir: PathBuf, + external_root: String, + listen_port: u16, + footer_copyright: Option<String> +} + +impl Config { + pub fn read_from_file<P: AsRef<Path>>(path: P) -> Result<Self, String> { + let config_contents = fs::read_to_string(&path) + .map_err(|_| "Unable to open config file".to_string())?; + + let file : ConfigFile = toml::from_str(&config_contents) + .map_err(|err| err.to_string())?; + + let port = file.listen_port.unwrap_or(3000); + + Ok(Self { + site_title: file.site_title + .unwrap_or("Untitled StormScribe Site".to_string()), + data_dir: file.data_dir.unwrap_or(path.as_ref() + .canonicalize().map_err(|_| "Cannot resolve config file location".to_string())? + .parent().ok_or("Cannot resolve data dir".to_string())?.to_path_buf()), + external_root: file.external_root + .unwrap_or(format!("http://localhost:{port}/")), + listen_port: port, + footer_copyright: file.footer_copyright, + }) + } +} diff --git a/src/data/mod.rs b/src/data/mod.rs new file mode 100644 index 0000000..bfe8b48 --- /dev/null +++ b/src/data/mod.rs @@ -0,0 +1,3 @@ +pub mod config; + +struct DirState diff --git a/src/data/pages.rs b/src/data/pages.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/data/pages.rs diff --git a/src/data/users.rs b/src/data/users.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/data/users.rs diff --git a/src/main.rs b/src/main.rs index ea22824..a9e3f1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +pub mod data; + use tokio::signal; #[cfg(feature = "ssr")] |