index : livejrnl-rs.git

ascending towards madness

author berrysweet <berrysweet@noreply.codeberg.org> 2023-07-05 20:08:54.0 +00:00:00
committer berrysweet <berrysweet@noreply.codeberg.org> 2023-07-05 20:08:54.0 +00:00:00
commit
104fa1d268d705d08a7835301c0dfd7a1d41aa71 [patch]
tree
a1043e82e3fbafcddafdb8c4ed2cd13044e9aff4
parent
7162f808fb33d424c3e0bd8b22088d96d51d44b6
download
104fa1d268d705d08a7835301c0dfd7a1d41aa71.tar.gz

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(-)

diff --git a/Cargo.toml b/Cargo.toml
index 0274868..3ff4829 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
confy = "0.5.1"
serde = { version = "1.0.164", features = ["derive"] }
\ No newline at end of file
diff --git a/src/data/formats.rs b/src/data/formats.rs
new file mode 100644
index 0000000..78701f3
--- /dev/null
+++ b/src/data/formats.rs
@@ -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
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..8cdfcec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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