mlem/src/config.rs

46 lines
1.2 KiB
Rust
Raw Normal View History

2024-04-09 17:28:56 +02:00
use serde::{Deserialize, Serialize};
2024-04-01 19:05:53 +02:00
use std::fs::read_to_string;
2024-04-09 17:28:56 +02:00
#[derive(Deserialize, Serialize, Debug)]
2024-04-01 19:05:53 +02:00
pub struct Config {
pub output_dir: String,
pub src_dir: String,
pub templates_dir: String,
2024-04-09 17:01:21 +02:00
pub emoji_config: Option<EmojiConfig>,
pub syndication: Option<Syndication>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct Syndication {
pub title: String,
pub link: String,
pub icon: Option<String>,
pub subtitle: Option<String>,
pub atom: Option<AtomConfig>,
2024-04-01 19:05:53 +02:00
}
#[derive(Deserialize, Serialize, Debug)]
pub struct AtomConfig {
pub enabled: bool,
}
2024-04-09 17:28:56 +02:00
#[derive(Deserialize, Serialize, Debug)]
2024-04-09 17:01:21 +02:00
pub struct EmojiConfig {
pub emoji_web_directory: String,
pub emoji_local_directory: String,
}
2024-04-09 17:23:37 +02:00
impl Default for Config {
fn default() -> Self {
2024-04-09 17:28:56 +02:00
Config {
output_dir: "output".to_string(),
src_dir: "md_src".to_string(),
templates_dir: "templates".to_string(),
emoji_config: None,
syndication: None,
2024-04-09 17:28:56 +02:00
}
2024-04-09 17:23:37 +02:00
}
}
2024-04-01 19:05:53 +02:00
pub fn read_config() -> Config {
let config_string = read_to_string("mlem.toml").expect("mlem.toml config not found");
toml::from_str(&config_string).unwrap()
}