starting config.yaml

This commit is contained in:
Tyrel Souza 2023-10-14 18:54:19 -04:00
parent bfeae64c84
commit d79924f70a
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
3 changed files with 31 additions and 1 deletions

2
config.yaml Normal file
View File

@ -0,0 +1,2 @@
links:
source: data/links.yaml

View File

@ -31,7 +31,8 @@ pub fn create_dirs(dirs: &[&str]) {
for dir in dirs {
let path = format!("./public/{}", dir);
if !Path::new(&path).exists() {
fs::create_dir(&path).expect("Could not create public directory");
let err = format!("Could not create {} directory", path);
fs::create_dir(&path).expect(&err);
}
}

View File

@ -1,8 +1,33 @@
mod links;
mod file_utils;
use crate::links::{load_links,render_links};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct LinksConfig {
source: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BlogConfig {
source: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
links: Option(LinksConfig),
blog: Option(BlogConfig),
}
fn load_config() {
let config_file = std::fs::File::open("./config.yaml").expect("Could not find config.yaml file");
let config: Config = serde_yaml::from_reader(config_file).expect("Could not read values");
println!("{:?}", config)
}
fn main() {
// absolutely destroy any /public data, so we have a clean slate to write to
file_utils::delete_public_dir();
@ -16,4 +41,6 @@ fn main() {
let links_output = render_links(links_input);
file_utils::write_file(links_output);
load_config();
}