|
@@ -38,7 +38,7 @@ pub struct Config { |
|
|
/// Description of the site |
|
|
/// Description of the site |
|
|
pub description: Option<String>, |
|
|
pub description: Option<String>, |
|
|
/// The language used in the site. Defaults to "en" |
|
|
/// The language used in the site. Defaults to "en" |
|
|
pub language_code: Option<String>, |
|
|
|
|
|
|
|
|
pub default_language: Option<String>, |
|
|
/// Whether to generate RSS. Defaults to false |
|
|
/// Whether to generate RSS. Defaults to false |
|
|
pub generate_rss: Option<bool>, |
|
|
pub generate_rss: Option<bool>, |
|
|
/// The number of articles to include in the RSS feed. Defaults to unlimited |
|
|
/// The number of articles to include in the RSS feed. Defaults to unlimited |
|
@@ -50,6 +50,9 @@ pub struct Config { |
|
|
/// Whether to compile the `sass` directory and output the css files into the static folder |
|
|
/// Whether to compile the `sass` directory and output the css files into the static folder |
|
|
pub compile_sass: Option<bool>, |
|
|
pub compile_sass: Option<bool>, |
|
|
|
|
|
|
|
|
|
|
|
/// Languages list and translated strings |
|
|
|
|
|
pub translations: Option<HashMap<String, Toml>>, |
|
|
|
|
|
|
|
|
/// All user params set in [extra] in the config |
|
|
/// All user params set in [extra] in the config |
|
|
pub extra: Option<HashMap<String, Toml>>, |
|
|
pub extra: Option<HashMap<String, Toml>>, |
|
|
|
|
|
|
|
@@ -74,13 +77,14 @@ impl Config { |
|
|
Err(e) => bail!(e) |
|
|
Err(e) => bail!(e) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
set_default!(config.language_code, "en".to_string()); |
|
|
|
|
|
|
|
|
set_default!(config.default_language, "en".to_string()); |
|
|
set_default!(config.highlight_code, false); |
|
|
set_default!(config.highlight_code, false); |
|
|
set_default!(config.generate_rss, false); |
|
|
set_default!(config.generate_rss, false); |
|
|
set_default!(config.rss_limit, 20); |
|
|
set_default!(config.rss_limit, 20); |
|
|
set_default!(config.generate_tags_pages, false); |
|
|
set_default!(config.generate_tags_pages, false); |
|
|
set_default!(config.generate_categories_pages, false); |
|
|
set_default!(config.generate_categories_pages, false); |
|
|
set_default!(config.compile_sass, false); |
|
|
set_default!(config.compile_sass, false); |
|
|
|
|
|
set_default!(config.translations, HashMap::new()); |
|
|
set_default!(config.extra, HashMap::new()); |
|
|
set_default!(config.extra, HashMap::new()); |
|
|
|
|
|
|
|
|
match config.highlight_theme { |
|
|
match config.highlight_theme { |
|
@@ -166,12 +170,13 @@ impl Default for Config { |
|
|
highlight_code: Some(true), |
|
|
highlight_code: Some(true), |
|
|
highlight_theme: Some("base16-ocean-dark".to_string()), |
|
|
highlight_theme: Some("base16-ocean-dark".to_string()), |
|
|
description: None, |
|
|
description: None, |
|
|
language_code: Some("en".to_string()), |
|
|
|
|
|
|
|
|
default_language: Some("en".to_string()), |
|
|
generate_rss: Some(false), |
|
|
generate_rss: Some(false), |
|
|
rss_limit: Some(10_000), |
|
|
rss_limit: Some(10_000), |
|
|
generate_tags_pages: Some(true), |
|
|
generate_tags_pages: Some(true), |
|
|
generate_categories_pages: Some(true), |
|
|
generate_categories_pages: Some(true), |
|
|
compile_sass: Some(false), |
|
|
compile_sass: Some(false), |
|
|
|
|
|
translations: None, |
|
|
extra: None, |
|
|
extra: None, |
|
|
build_timestamp: Some(1), |
|
|
build_timestamp: Some(1), |
|
|
} |
|
|
} |
|
@@ -302,4 +307,27 @@ a_value = 10 |
|
|
assert_eq!(extra["hello"].as_str().unwrap(), "world".to_string()); |
|
|
assert_eq!(extra["hello"].as_str().unwrap(), "world".to_string()); |
|
|
assert_eq!(extra["a_value"].as_integer().unwrap(), 10); |
|
|
assert_eq!(extra["a_value"].as_integer().unwrap(), 10); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
fn can_use_language_configuration() { |
|
|
|
|
|
let config = r#" |
|
|
|
|
|
base_url = "https://remplace-par-ton-url.fr" |
|
|
|
|
|
default_language = "fr" |
|
|
|
|
|
|
|
|
|
|
|
[translations] |
|
|
|
|
|
[translations.fr] |
|
|
|
|
|
title = "Un titre" |
|
|
|
|
|
|
|
|
|
|
|
[translations.en] |
|
|
|
|
|
title = "A title" |
|
|
|
|
|
|
|
|
|
|
|
"#; |
|
|
|
|
|
|
|
|
|
|
|
let config = Config::parse(config); |
|
|
|
|
|
assert!(config.is_ok()); |
|
|
|
|
|
let translations = config.unwrap().translations.unwrap(); |
|
|
|
|
|
assert_eq!(translations["fr"]["title"].as_str().unwrap(), "Un titre"); |
|
|
|
|
|
assert_eq!(translations["en"]["title"].as_str().unwrap(), "A title"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |