From 7099fc8ac291b9d671ae6d09ec4c7c7d34d30f10 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Tue, 9 May 2017 20:39:40 +0900 Subject: [PATCH] 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 --- Cargo.lock | 6 +++--- src/front_matter.rs | 12 ++++++++++++ src/site.rs | 3 +++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 406f4b9f..5737d73a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ dependencies = [ "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)", "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)", "toml 0.4.0 (git+https://github.com/alexcrichton/toml-rs)", "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -820,7 +820,7 @@ dependencies = [ [[package]] name = "tera" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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 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 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-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" diff --git a/src/front_matter.rs b/src/front_matter.rs index 09da15ec..c53e2f54 100644 --- a/src/front_matter.rs +++ b/src/front_matter.rs @@ -58,6 +58,9 @@ pub struct FrontMatter { /// Path to be used by pagination: the page number will be appended after it. Defaults to `page`. #[serde(skip_serializing)] pub paginate_path: Option, + /// Whether to render that page/section or not. Defaults to `true`. + #[serde(skip_serializing)] + pub render: Option, /// Any extra parameter present in the front matter pub extra: Option>, } @@ -85,6 +88,10 @@ impl FrontMatter { f.paginate_path = Some("page".to_string()); } + if f.render.is_none() { + f.render = Some(true); + } + Ok(f) } @@ -121,6 +128,10 @@ impl FrontMatter { None => false } } + + pub fn should_render(&self) -> bool { + self.render.unwrap() + } } impl Default for FrontMatter { @@ -139,6 +150,7 @@ impl Default for FrontMatter { template: None, paginate_by: None, paginate_path: None, + render: None, extra: None, } } diff --git a/src/site.rs b/src/site.rs index 43340a32..f5ffdaae 100644 --- a/src/site.rs +++ b/src/site.rs @@ -548,6 +548,9 @@ impl Site { .collect(); for section in self.sections.values() { + if !section.meta.should_render() { + continue; + } let mut output_path = public.to_path_buf(); for component in §ion.components { output_path.push(component);