diff --git a/src/config.rs b/src/config.rs index 3c66fce..9a7c8a1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,17 +7,25 @@ use std::{fs::File, io::Write, path::Path}; use crate::template::Template; +/// Store the configuration of config/config.toml #[derive(Deserialize, Clone, Default)] pub struct FileConfig { + /// http/https pub scheme: Option, + /// Port used pub port: Option, + /// Mail of owner pub mail: Option, + /// Lang used pub lang: Option, + /// Adress .onion for Tor pub onion: Option, + /// App name pub app_name: Option, } impl FileConfig { + /// Initialize with default values fn new() -> Self { Self { scheme: Some("http".to_owned()), @@ -27,6 +35,7 @@ impl FileConfig { } } + /// Complete default structure with an existing one fn complete(a: Self) -> Self { // Default config let d = FileConfig::new(); @@ -51,13 +60,18 @@ impl FileConfig { } } +/// Configuration used internally in the app #[derive(Clone)] pub struct Config { + /// Information given in the config file pub fc: FileConfig, + /// Location where the static files are stored pub static_location: String, + /// Informations about templates pub tmpl: Template, } +/// Load the config file fn get_file_config(file_path: &str) -> FileConfig { match fs::read_to_string(file_path) { Ok(file) => match toml::from_str(&file) { @@ -66,14 +80,14 @@ fn get_file_config(file_path: &str) -> FileConfig { panic!("Error in config file: {file_error}"); } }, - Err(_) => - // No config file - { + Err(_) => { + // No config file FileConfig::new() } } } +/// Build the configuration pub fn get_config(file_path: &str) -> Config { let internal_config = get_file_config(file_path); @@ -91,6 +105,7 @@ pub fn get_config(file_path: &str) -> Config { } } +/// Preparation before running the http server fn init(dist_dir: String, static_dir: String, templates_dir: String) -> String { // The static folder is minimized only in release mode if cfg!(debug_assertions) { @@ -127,6 +142,7 @@ fn init(dist_dir: String, static_dir: String, templates_dir: String) -> String { } } +/// Minify some assets for production fn minify_and_copy(cfg: &Cfg, path: PathBuf, path_with_dist: String) { // Create folders let new_path = Path::new(&path_with_dist); diff --git a/src/template.rs b/src/template.rs index 3361461..5e500c7 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,11 +1,15 @@ use ramhorns::{Content, Ramhorns}; +/// Structure used in the config variable of the app #[derive(Clone)] pub struct Template { + /// Root directory where templates are stored pub directory: String, + /// App name pub app_name: String, } +/// Structure used by /routes/*.rs #[derive(Default)] pub struct Infos { /// Title @@ -16,12 +20,18 @@ pub struct Infos { pub page_kw: Option, } +/// Final structure given to template #[derive(Content)] struct Data { + /// App name app_name: String, + /// Title of the page page_title: Option, + /// Description of the page page_desc: Option, + /// Keywords of the the page page_kw: Option, + /// Data needed to render the page data: T, }