1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use serde_derive::{Deserialize, Serialize};
use toml::from_str;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Config {
    pub base_url: String,
    pub site_name: String,
    pub site_author: String,
    pub site_description: String,
    pub post_headers: Vec<String>,
}

impl Config {
    pub fn read_config(toml_text: &str) -> Config {
        let config: Config = from_str(toml_text).expect("could not parse the config file");
        config
    }
    pub fn get_defaults() -> Config {
        Config {
            base_url: String::from(""),
            site_name: String::from("STOG"),
            site_author: String::from("Somebody"),
            site_description: String::from("generated with STOG"),
            post_headers: vec![
                String::from("\"title\""),
                String::from("\"date\""),
                String::from("\"author\""),
            ],
        }
    }
}