Add frontmatter flag to not render a section

Useful if you're creating a section only to access it in the index but
do not want a section page for it
This commit is contained in:
Vincent Prouillet 2017-05-09 20:39:40 +09:00
parent 4df9752b54
commit 7099fc8ac2
3 changed files with 18 additions and 3 deletions

6
Cargo.lock generated
View file

@ -19,7 +19,7 @@ dependencies = [
"staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "staticfile 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syntect 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "syntect 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"tera 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
"term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.4.0 (git+https://github.com/alexcrichton/toml-rs)", "toml 0.4.0 (git+https://github.com/alexcrichton/toml-rs)",
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -820,7 +820,7 @@ dependencies = [
[[package]] [[package]]
name = "tera" name = "tera"
version = "0.10.2" version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1165,7 +1165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum syntect 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24204b1f4bdd49f84e5f4b219d0bf1dc45ac2fd7fc46320ab6627b537d6d4b69" "checksum syntect 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24204b1f4bdd49f84e5f4b219d0bf1dc45ac2fd7fc46320ab6627b537d6d4b69"
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" "checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
"checksum tera 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d09d7a9a4ef4da73121c89842ab00213528804b9992001955871cd6ee49d66c" "checksum tera 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "86bc1156f5502b5eb3904348f4bea155d728e51fec7c981c44b3f1d10b8e574b"
"checksum term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d168af3930b369cfe245132550579d47dfd873d69470755a19c2c6568dbbd989" "checksum term 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d168af3930b369cfe245132550579d47dfd873d69470755a19c2c6568dbbd989"
"checksum term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ab900bf2f05175932b13d4fc12f8ff09ef777715b04998791ab2c930841e496b" "checksum term-painter 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ab900bf2f05175932b13d4fc12f8ff09ef777715b04998791ab2c930841e496b"
"checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209"

View file

@ -58,6 +58,9 @@ pub struct FrontMatter {
/// Path to be used by pagination: the page number will be appended after it. Defaults to `page`. /// Path to be used by pagination: the page number will be appended after it. Defaults to `page`.
#[serde(skip_serializing)] #[serde(skip_serializing)]
pub paginate_path: Option<String>, pub paginate_path: Option<String>,
/// Whether to render that page/section or not. Defaults to `true`.
#[serde(skip_serializing)]
pub render: Option<bool>,
/// Any extra parameter present in the front matter /// Any extra parameter present in the front matter
pub extra: Option<HashMap<String, Value>>, pub extra: Option<HashMap<String, Value>>,
} }
@ -85,6 +88,10 @@ impl FrontMatter {
f.paginate_path = Some("page".to_string()); f.paginate_path = Some("page".to_string());
} }
if f.render.is_none() {
f.render = Some(true);
}
Ok(f) Ok(f)
} }
@ -121,6 +128,10 @@ impl FrontMatter {
None => false None => false
} }
} }
pub fn should_render(&self) -> bool {
self.render.unwrap()
}
} }
impl Default for FrontMatter { impl Default for FrontMatter {
@ -139,6 +150,7 @@ impl Default for FrontMatter {
template: None, template: None,
paginate_by: None, paginate_by: None,
paginate_path: None, paginate_path: None,
render: None,
extra: None, extra: None,
} }
} }

View file

@ -548,6 +548,9 @@ impl Site {
.collect(); .collect();
for section in self.sections.values() { for section in self.sections.values() {
if !section.meta.should_render() {
continue;
}
let mut output_path = public.to_path_buf(); let mut output_path = public.to_path_buf();
for component in &section.components { for component in &section.components {
output_path.push(component); output_path.push(component);