teascade-generator/src/config_toml.rs

121 lines
3.0 KiB
Rust
Raw Normal View History

2018-04-16 13:10:05 +02:00
use std::path::PathBuf;
2018-04-16 14:21:31 +02:00
use std::collections::HashMap;
2018-04-16 13:10:05 +02:00
use error::Error;
2018-04-20 01:52:48 +02:00
use file_writer;
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 13:10:05 +02:00
pub struct GlobalConfigToml {
pub website: WebsiteConfig,
2018-04-16 14:21:31 +02:00
pub navbar: Option<NavbarConfig>,
2018-04-19 00:12:18 +02:00
#[serde(rename = "resource")]
pub resources: Option<HashMap<String, ResourceConfig>>,
pub twitter: Option<TwitterConfig>,
pub google: Option<GoogleConfig>,
2018-04-19 00:12:18 +02:00
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct ResourceConfig {
pub source: String,
pub destination: String,
2018-04-16 13:10:05 +02:00
}
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 13:10:05 +02:00
pub struct WebsiteConfig {
pub website_name: String,
pub built_pages: Vec<String>,
pub use_default_css: bool,
2018-04-19 21:21:49 +02:00
pub use_default_js: bool,
2018-04-16 13:10:05 +02:00
pub javascript: Vec<String>,
pub css: Vec<String>,
2018-04-16 13:10:05 +02:00
pub favicon: Option<String>,
pub before_navbar_url: Option<String>,
pub before_content_url: Option<String>,
pub after_content_url: Option<String>,
pub mobile_viewport: Option<bool>,
pub meta_description: Option<bool>,
pub charset: Option<String>,
pub meta_og: Option<bool>,
2018-04-19 00:42:12 +02:00
pub output: Option<String>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct GoogleConfig {
pub google_robots: String,
pub google_site_verification: String,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct TwitterConfig {
pub twitter_site: String,
pub twitter_creator: String,
2018-04-16 13:10:05 +02:00
}
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 14:21:31 +02:00
pub struct NavbarConfig {
pub items: Vec<String>,
#[serde(rename = "item")]
pub item_map: HashMap<String, NavbarItem>,
}
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 14:21:31 +02:00
pub struct NavbarItem {
pub title: String,
pub link: String,
pub image_url: Option<String>,
}
2018-04-16 13:10:05 +02:00
impl GlobalConfigToml {
pub fn get_config() -> Result<GlobalConfigToml, Error> {
2018-04-20 01:52:48 +02:00
file_writer::get_toml(&PathBuf::from("config.toml"))
2018-04-16 13:10:05 +02:00
}
}
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 13:10:05 +02:00
pub struct PageConfigToml {
pub page: PageConfig,
}
impl PageConfigToml {
pub fn get_from(path: &PathBuf) -> Result<PageConfigToml, Error> {
2018-04-20 01:52:48 +02:00
file_writer::get_toml(path)
2018-04-16 13:10:05 +02:00
}
}
2018-04-16 23:31:44 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
2018-04-16 13:10:05 +02:00
pub struct PageConfig {
2018-04-16 14:21:31 +02:00
pub html_path: String,
2018-04-16 13:10:05 +02:00
pub title: String,
pub description: String,
pub content_path: String,
pub favicon: Option<String>,
pub before_navbar_url: Option<String>,
pub before_content_url: Option<String>,
pub after_content_url: Option<String>,
2018-04-16 13:10:05 +02:00
pub javascript: Option<Vec<String>>,
pub css: Option<Vec<String>>,
}
2018-04-20 01:52:48 +02:00
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct InjectionToml {
pub meta: MetaInjectionToml,
pub list: HashMap<String, HashMap<String, String>>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct MetaInjectionToml {
pub rendered: Vec<String>,
pub template: String,
pub list_classes: String,
pub is_list: bool,
}
impl InjectionToml {
pub fn get_from(path: &PathBuf) -> Result<InjectionToml, Error> {
file_writer::get_toml(path)
}
}