123 lines
3.1 KiB
Rust
123 lines
3.1 KiB
Rust
use std::collections::HashMap;
|
|
use std::path::PathBuf;
|
|
|
|
use serde_derive::{Deserialize, Serialize};
|
|
|
|
use crate::error::Error;
|
|
use crate::file_writer;
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct GlobalConfigToml {
|
|
pub website: WebsiteConfig,
|
|
pub navbar: Option<NavbarConfig>,
|
|
#[serde(rename = "resource")]
|
|
pub resources: Option<HashMap<String, ResourceConfig>>,
|
|
pub twitter: Option<TwitterConfig>,
|
|
pub google: Option<GoogleConfig>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct ResourceConfig {
|
|
pub source: String,
|
|
pub destination: String,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct WebsiteConfig {
|
|
pub website_name: String,
|
|
pub built_pages: Vec<String>,
|
|
pub use_default_css: bool,
|
|
pub use_default_js: bool,
|
|
pub javascript: Vec<String>,
|
|
pub css: Vec<String>,
|
|
|
|
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>,
|
|
|
|
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,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct NavbarConfig {
|
|
pub items: Vec<String>,
|
|
#[serde(rename = "item")]
|
|
pub item_map: HashMap<String, NavbarItem>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct NavbarItem {
|
|
pub title: String,
|
|
pub link: String,
|
|
pub image_url: Option<String>,
|
|
}
|
|
|
|
impl GlobalConfigToml {
|
|
pub fn get_config() -> Result<GlobalConfigToml, Error> {
|
|
file_writer::get_toml(&PathBuf::from("config.toml"))
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct PageConfigToml {
|
|
pub page: PageConfig,
|
|
}
|
|
|
|
impl PageConfigToml {
|
|
pub fn get_from(path: &PathBuf) -> Result<PageConfigToml, Error> {
|
|
file_writer::get_toml(path)
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, Clone, Debug)]
|
|
pub struct PageConfig {
|
|
pub html_path: String,
|
|
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>,
|
|
pub javascript: Option<Vec<String>>,
|
|
pub css: Option<Vec<String>>,
|
|
}
|
|
|
|
#[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)
|
|
}
|
|
}
|