A small, fast, static site generator
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 111 lines 2.6 kB view raw
1use anyhow::Result; 2use serde::{Deserialize, Serialize}; 3use std::collections::HashMap; 4 5#[derive(Debug, Deserialize, Default)] 6pub struct Config { 7 #[serde(default)] 8 pub site: Site, 9 #[serde(default)] 10 pub build: Build, 11 #[serde(default)] 12 pub serve: Serve, 13 #[serde(default)] 14 pub extra: HashMap<String, toml::Value>, 15} 16 17#[derive(Debug, Serialize, Deserialize)] 18pub struct Site { 19 pub title: Option<String>, 20 pub base_url: Option<String>, 21 pub author: Option<String>, 22 pub description: Option<String>, 23 #[serde(default = "default_template_name")] 24 pub default_template: String, 25} 26 27#[derive(Debug, Serialize, Deserialize)] 28pub struct Build { 29 #[serde(default = "default_content_dir")] 30 pub content_dir: String, 31 #[serde(default = "default_template_dir")] 32 pub template_dir: String, 33 #[serde(default = "default_static_dir")] 34 pub static_dir: String, 35 #[serde(default = "default_build_dir")] 36 pub build_dir: String, 37 #[serde(default)] 38 pub drafts: bool, 39} 40 41#[derive(Debug, Serialize, Deserialize)] 42pub struct Serve { 43 #[serde(default = "default_serve_host")] 44 pub host: String, 45 #[serde(default = "default_serve_port")] 46 pub port: u16, 47} 48 49impl Default for Site { 50 fn default() -> Self { 51 Self { 52 title: None, 53 base_url: None, 54 author: None, 55 description: None, 56 default_template: default_template_name(), 57 } 58 } 59} 60 61impl Default for Build { 62 fn default() -> Self { 63 Self { 64 content_dir: default_content_dir(), 65 template_dir: default_template_dir(), 66 static_dir: default_static_dir(), 67 build_dir: default_build_dir(), 68 drafts: false, 69 } 70 } 71} 72 73impl Default for Serve { 74 fn default() -> Self { 75 Self { 76 host: default_serve_host(), 77 port: default_serve_port(), 78 } 79 } 80} 81 82fn default_template_name() -> String { 83 "default.html".to_string() 84} 85fn default_content_dir() -> String { 86 "content".to_string() 87} 88fn default_static_dir() -> String { 89 "static".to_string() 90} 91fn default_template_dir() -> String { 92 "template".to_string() 93} 94fn default_build_dir() -> String { 95 "build".to_string() 96} 97fn default_serve_host() -> String { 98 "127.0.0.1".to_string() 99} 100fn default_serve_port() -> u16 { 101 8080u16 102} 103 104impl Config { 105 pub fn from_file(path: &str) -> Result<Self> { 106 let data = std::fs::read_to_string(path)?; 107 let cfg: Self = toml::from_str(&data)?; 108 109 Ok(cfg) 110 } 111}