@@ -31,11 +31,23 @@ pub struct Config { | |||
pub language_code: Option<String>, | |||
/// Whether to generate RSS, defaults to false | |||
pub generate_rss: Option<bool>, | |||
/// Whether to generate tags and individual tag pages if some pages have them. Defaults to true | |||
pub generate_tags_pages: Option<bool>, | |||
/// Whether to generate categories and individual tag categories if some pages have them. Defaults to true | |||
pub generate_categories_pages: Option<bool>, | |||
/// All user params set in [extra] in the config | |||
pub extra: Option<HashMap<String, Toml>>, | |||
} | |||
macro_rules! set_default { | |||
($key: expr, $default: expr) => { | |||
if $key.is_none() { | |||
$key = Some($default); | |||
} | |||
} | |||
} | |||
impl Config { | |||
/// Parses a string containing TOML to our Config struct | |||
/// Any extra parameter will end up in the extra field | |||
@@ -45,13 +57,8 @@ impl Config { | |||
Err(e) => bail!(e) | |||
}; | |||
if config.language_code.is_none() { | |||
config.language_code = Some("en".to_string()); | |||
} | |||
if config.highlight_code.is_none() { | |||
config.highlight_code = Some(false); | |||
} | |||
set_default!(config.language_code, "en".to_string()); | |||
set_default!(config.highlight_code, false); | |||
match config.highlight_theme { | |||
Some(ref t) => { | |||
@@ -62,9 +69,9 @@ impl Config { | |||
None => config.highlight_theme = Some("base16-ocean-dark".to_string()) | |||
}; | |||
if config.generate_rss.is_none() { | |||
config.generate_rss = Some(false); | |||
} | |||
set_default!(config.generate_rss, false); | |||
set_default!(config.generate_tags_pages, true); | |||
set_default!(config.generate_categories_pages, true); | |||
Ok(config) | |||
} | |||
@@ -100,6 +107,8 @@ impl Default for Config { | |||
description: None, | |||
language_code: Some("en".to_string()), | |||
generate_rss: Some(false), | |||
generate_tags_pages: Some(true), | |||
generate_categories_pages: Some(true), | |||
extra: None, | |||
} | |||
} | |||
@@ -269,8 +269,12 @@ impl Site { | |||
} | |||
// Outputting categories and pages | |||
self.render_categories_and_tags(RenderList::Categories)?; | |||
self.render_categories_and_tags(RenderList::Tags)?; | |||
if self.config.generate_categories_pages.unwrap() { | |||
self.render_categories_and_tags(RenderList::Categories)?; | |||
} | |||
if self.config.generate_tags_pages.unwrap() { | |||
self.render_categories_and_tags(RenderList::Tags)?; | |||
} | |||
// And finally the index page | |||
let mut context = Context::new(); | |||
@@ -368,23 +372,27 @@ impl Site { | |||
context.add("sections", &self.sections.values().collect::<Vec<&Section>>()); | |||
let mut categories = vec![]; | |||
if !self.categories.is_empty() { | |||
categories.push(self.config.make_permalink("categories")); | |||
for category in self.categories.keys() { | |||
categories.push( | |||
self.config.make_permalink(&format!("categories/{}", slugify(category))) | |||
); | |||
if self.config.generate_categories_pages.unwrap() { | |||
if !self.categories.is_empty() { | |||
categories.push(self.config.make_permalink("categories")); | |||
for category in self.categories.keys() { | |||
categories.push( | |||
self.config.make_permalink(&format!("categories/{}", slugify(category))) | |||
); | |||
} | |||
} | |||
} | |||
context.add("categories", &categories); | |||
let mut tags = vec![]; | |||
if !self.tags.is_empty() { | |||
tags.push(self.config.make_permalink("tags")); | |||
for tag in self.tags.keys() { | |||
tags.push( | |||
self.config.make_permalink(&format!("tags/{}", slugify(tag))) | |||
); | |||
if self.config.generate_tags_pages.unwrap() { | |||
if !self.tags.is_empty() { | |||
tags.push(self.config.make_permalink("tags")); | |||
for tag in self.tags.keys() { | |||
tags.push( | |||
self.config.make_permalink(&format!("tags/{}", slugify(tag))) | |||
); | |||
} | |||
} | |||
} | |||
context.add("tags", &tags); | |||