feat: add loading config files
Diff
Cargo.toml | 2 ++
src/data/formats.rs | 23 +++++++++++++++++++++++
src/main.rs | 19 ++++++++++++++++++-
3 files changed, 43 insertions(+), 1 deletion(-)
@@ -6,3 +6,5 @@ edition = "2021"
[dependencies]
confy = "0.5.1"
serde = { version = "1.0.164", features = ["derive"] }
\ No newline at end of file
@@ -0,0 +1,23 @@
use serde::Serialize;
use serde::Deserialize;
#[derive(Debug, Serialize, Deserialize)]
pub struct RenderConfig {
pub site_name: String,
pub base_url: String,
pub author: String,
pub template: String,
pub site_description: String,
}
impl ::std::default::Default for RenderConfig {
fn default() -> Self {
Self {
site_name: String::from("livejrnl-rs"),
base_url: String::from("localhost"),
author: String::from("me"),
template: String::from("/dev/null"),
site_description:String::from("This is a site rendered with livejrnl-rs.").into()
}
}
}
\ No newline at end of file
@@ -1,3 +1,20 @@
mod data {
pub mod formats;
}
const APP_NAME: &str = "livejrnl-rs";
fn main() {
println!("Hello, world!");
let config_data = load_config();
match config_data {
Ok(config_data) => {
println!("{:#?}", config_data);
},
Err(error) => println!("{:#?}", error)
};
}
fn load_config() -> Result<data::formats::RenderConfig, confy::ConfyError> {
let cfg: data::formats::RenderConfig = confy::load(APP_NAME, "config")?;
Ok(cfg)
}
\ No newline at end of file