1use serde_derive::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Debug, Clone)]
4pub struct Config {
5 pub base_url: String,
6 pub site_name: String,
7 pub site_author: String,
8 pub site_description: String,
9 pub build_dirs: Vec<(String, String, bool)>,
10 pub public_dir: String,
11 pub templates_dir: String,
12 pub output_dir: String,
13}
14
15impl Config {
16 pub fn read_config(toml_text: &str) -> Config {
17 let config: Config = toml::from_str(toml_text).expect("could not parse the config file");
18 config
19 }
20 pub fn get_defaults_string() -> String {
21 let default_config = Config {
22 base_url: String::from(""),
23 site_name: String::from("STOG"),
24 site_author: String::from("Somebody"),
25 site_description: String::from("generated with STOG"),
26 build_dirs: vec![(String::from("_posts"), String::from("posts"), true)],
27 public_dir: String::from("public"),
28 templates_dir: String::from("_templates"),
29 output_dir: String::from("_build"),
30 };
31
32 toml::to_string_pretty(&default_config).unwrap()
33 }
34}