diff --git a/CHANGELOG.md b/CHANGELOG.md index 20c076c..f0e909e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ sections up to the index to be used with the `get_section` Tera function - Add a `watch-only` flag to the `serve` command for when you don't want a webserver - Add `transparent` sections, for when you want to separate content by sections but want to group them at a higher level (think a `posts` folder with years that want to use pagination on the index). +- Add `page_template` to section front-matter for when you want to specify the template to use for every page under it ## 0.4.2 (2018-09-03) diff --git a/Cargo.lock b/Cargo.lock index 56d8296..999ace2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,7 +84,7 @@ dependencies = [ "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -98,7 +98,7 @@ dependencies = [ "tokio-reactor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -135,7 +135,7 @@ dependencies = [ "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "tendril 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -240,11 +240,6 @@ name = "bitflags" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "bitflags" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "bitflags" version = "1.0.4" @@ -351,7 +346,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -535,7 +530,7 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rust-stemmers 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -714,7 +709,7 @@ dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "errors 0.1.0", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -821,7 +816,7 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -969,7 +964,7 @@ dependencies = [ "image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)", "utils 0.1.0", ] @@ -1094,7 +1089,7 @@ dependencies = [ "globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rendering 0.1.0", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1617,10 +1612,10 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1720,7 +1715,7 @@ dependencies = [ [[package]] name = "regex" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1756,7 +1751,7 @@ dependencies = [ "link_checker 0.1.0", "pest 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest_derive 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1788,7 +1783,7 @@ dependencies = [ "serde_urlencoded 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1957,7 +1952,7 @@ dependencies = [ "dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2186,12 +2181,12 @@ dependencies = [ "imageproc 0.1.0", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "library 0.1.0", - "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.11.19 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "utils 0.1.0", ] @@ -2217,12 +2212,12 @@ dependencies = [ "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest_derive 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", "slug 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2485,7 +2480,7 @@ dependencies = [ "tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2508,7 +2503,7 @@ dependencies = [ "tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2665,7 +2660,7 @@ dependencies = [ [[package]] name = "url" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2826,7 +2821,7 @@ dependencies = [ "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2871,7 +2866,7 @@ dependencies = [ "site 0.1.0", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "utils 0.1.0", "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2896,7 +2891,6 @@ dependencies = [ "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" @@ -3044,7 +3038,7 @@ dependencies = [ "checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b" "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" -"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" +"checksum pulldown-cmark 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eef52fac62d0ea7b9b4dc7da092aa64ea7ec3d90af6679422d3d7e0e14b6ee15" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "63b5829244f52738cfee93b3a165c1911388675be000c888d2fae620dee8fa5b" "checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" @@ -3055,7 +3049,7 @@ dependencies = [ "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341" +"checksum regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ee84f70c8c08744ea9641a731c7fadb475bf2ecc52d7f627feb833e0b3990467" "checksum regex-syntax 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "747ba3b235651f6e2f67dfa8bcdcd073ddb7c243cb21c442fc12395dfcac212d" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum reqwest 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "00a5870d8edc74fc6e1eb58edbd2815d2243e1a2255d6bf9c82a7a875901b5db" @@ -3146,7 +3140,7 @@ dependencies = [ "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" +"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf-8 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bab35f71693630bb1953dce0f2bcd780e7cde025027124a202ac08a45ba25141" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum uuid 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dab5c5526c5caa3d106653401a267fed923e7046f35895ffcb5ca42db64942e6" diff --git a/components/front_matter/src/section.rs b/components/front_matter/src/section.rs index fe61e37..e0215aa 100644 --- a/components/front_matter/src/section.rs +++ b/components/front_matter/src/section.rs @@ -55,6 +55,9 @@ pub struct SectionFrontMatter { /// sections for each year under a posts section. #[serde(skip_serializing)] pub transparent: bool, + /// Optional template for all pages in this section (including the pages of children section) + #[serde(skip_serializing)] + pub page_template: Option, /// Any extra parameter present in the front matter pub extra: HashMap, } @@ -93,6 +96,7 @@ impl Default for SectionFrontMatter { insert_anchor_links: InsertAnchor::None, in_search_index: true, transparent: false, + page_template: None, extra: HashMap::new(), } } diff --git a/components/library/src/library.rs b/components/library/src/library.rs index aff16df..8fccb3f 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -129,18 +129,36 @@ impl Library { for (key, page) in &mut self.pages { let mut parent_section_path = page.file.parent.join("_index.md"); while let Some(section_key) = self.paths_to_sections.get(&parent_section_path) { - let mut section = self.sections.get_mut(*section_key).unwrap(); - section.pages.push(key); + let parent_is_transparent; + // We need to get a reference to a section later so keep the scope of borrowing small + { + let mut section = self.sections.get_mut(*section_key).unwrap(); + section.pages.push(key); + parent_is_transparent = section.meta.transparent; + } page.ancestors = ancestors.get(&parent_section_path).cloned().unwrap_or_else(|| vec![]); // Don't forget to push the actual parent page.ancestors.push(*section_key); - if !section.meta.transparent { + // Find the page template if one of a parent has page_template set + // Stops after the first one found, keep in mind page.ancestors + // is [index, ..., parent] so we need to reverse it first + if page.meta.template.is_none() { + for ancestor in page.ancestors.iter().rev() { + let s = self.sections.get(*ancestor).unwrap(); + if s.meta.page_template.is_some() { + page.meta.template = s.meta.page_template.clone(); + break; + } + } + } + + if !parent_is_transparent { break; } - // We've added `_index.md` if we are here so we need to go up twice + // We've added `_index.md` so if we are here so we need to go up twice match parent_section_path.clone().parent().unwrap().parent() { Some(parent) => parent_section_path = parent.join("_index.md"), None => break, @@ -303,6 +321,10 @@ impl Library { self.pages.get(key).unwrap() } + pub fn get_page_mut_by_key(&mut self, key: Key) -> &mut Page { + self.pages.get_mut(key).unwrap() + } + pub fn remove_section(&mut self, path: &PathBuf) -> Option
{ if let Some(k) = self.paths_to_sections.remove(path) { self.sections.remove(k) diff --git a/components/rebuild/src/lib.rs b/components/rebuild/src/lib.rs index 7e3e3d7..4a6f5f9 100644 --- a/components/rebuild/src/lib.rs +++ b/components/rebuild/src/lib.rs @@ -60,6 +60,8 @@ fn find_section_front_matter_changes( return changes_needed; } + + if current.paginate_by != new.paginate_by || current.paginate_path != new.paginate_path || current.insert_anchor_links != new.insert_anchor_links diff --git a/components/rendering/Cargo.toml b/components/rendering/Cargo.toml index 603e662..b7319b1 100644 --- a/components/rendering/Cargo.toml +++ b/components/rendering/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Vincent Prouillet "] [dependencies] tera = { version = "0.11", features = ["preserve_order"] } syntect = "3" -pulldown-cmark = "0" +pulldown-cmark = "0.2" slug = "0.1" serde = "1" serde_derive = "1" diff --git a/components/rendering/src/markdown.rs b/components/rendering/src/markdown.rs index 415de95..7dde02a 100644 --- a/components/rendering/src/markdown.rs +++ b/components/rendering/src/markdown.rs @@ -1,6 +1,6 @@ use std::borrow::Cow::{Borrowed, Owned}; -use self::cmark::{Event, Options, Parser, Tag, OPTION_ENABLE_FOOTNOTES, OPTION_ENABLE_TABLES}; +use self::cmark::{Event, Options, Parser, Tag}; use pulldown_cmark as cmark; use slug::slugify; use syntect::easy::HighlightLines; @@ -69,8 +69,8 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Resulttest"# )); } + +#[test] +fn can_apply_page_templates() { + let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf(); + path.push("test_site"); + let mut site = Site::new(&path, "config.toml").unwrap(); + site.load().unwrap(); + + let template_path = path.join("content").join("applying_page_template"); + + let template_section = site.library.get_section(&template_path.join("_index.md")).unwrap(); + assert_eq!(template_section.subsections.len(), 1); + assert_eq!(template_section.pages.len(), 2); + + let from_section_config = site.library.get_page_by_key(template_section.pages[0]); + assert_eq!(from_section_config.meta.template, Some("page_template.html".into())); + assert_eq!(from_section_config.meta.title, Some("From section config".into())); + + let override_page_template = site.library.get_page_by_key(template_section.pages[1]); + assert_eq!(override_page_template.meta.template, Some("page_template_override.html".into())); + assert_eq!(override_page_template.meta.title, Some("Override".into())); + + // It should have applied recursively as well + let another_section = site.library.get_section(&template_path.join("another_section").join("_index.md")).unwrap(); + assert_eq!(another_section.subsections.len(), 0); + assert_eq!(another_section.pages.len(), 1); + + let changed_recursively = site.library.get_page_by_key(another_section.pages[0]); + assert_eq!(changed_recursively.meta.template, Some("page_template.html".into())); + assert_eq!(changed_recursively.meta.title, Some("Changed recursively".into())); +} diff --git a/components/templates/Cargo.toml b/components/templates/Cargo.toml index 3676f3b..c3001f4 100644 --- a/components/templates/Cargo.toml +++ b/components/templates/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Vincent Prouillet "] tera = "0.11" base64 = "0.10" lazy_static = "1" -pulldown-cmark = "0" +pulldown-cmark = "0.2" toml = "0.4" csv = "1" serde_json = "1.0" diff --git a/components/templates/src/filters.rs b/components/templates/src/filters.rs index 1537351..901c0f6 100644 --- a/components/templates/src/filters.rs +++ b/components/templates/src/filters.rs @@ -12,8 +12,8 @@ pub fn markdown(value: Value, args: HashMap) -> TeraResult }; let mut opts = cmark::Options::empty(); - opts.insert(cmark::OPTION_ENABLE_TABLES); - opts.insert(cmark::OPTION_ENABLE_FOOTNOTES); + opts.insert(cmark::Options::ENABLE_TABLES); + opts.insert(cmark::Options::ENABLE_FOOTNOTES); let mut html = String::new(); let parser = cmark::Parser::new_ext(&s, opts); diff --git a/docs/content/documentation/content/section.md b/docs/content/documentation/content/section.md index dbca212..ec3669a 100644 --- a/docs/content/documentation/content/section.md +++ b/docs/content/documentation/content/section.md @@ -49,6 +49,13 @@ weight = 0 # Template to use to render this section page template = "section.html" +# Apply the given template to ALL pages below the section, recursively. +# If you have several nested sections each with a page_template set, the page +# will always use the closest to itself. +# However, a page own `template` variable will always have priority. +# Not set by default +page_template = + # How many pages to be displayed per paginated page. # No pagination will happen if this isn't set or if the value is 0 paginate_by = 0 diff --git a/test_site/content/applying_page_template/_index.md b/test_site/content/applying_page_template/_index.md new file mode 100644 index 0000000..f55abf1 --- /dev/null +++ b/test_site/content/applying_page_template/_index.md @@ -0,0 +1,4 @@ ++++ +page_template = "page_template.html" +sort_by = "weight" ++++ diff --git a/test_site/content/applying_page_template/another_section/_index.md b/test_site/content/applying_page_template/another_section/_index.md new file mode 100644 index 0000000..ac36e06 --- /dev/null +++ b/test_site/content/applying_page_template/another_section/_index.md @@ -0,0 +1,2 @@ ++++ ++++ diff --git a/test_site/content/applying_page_template/another_section/post.md b/test_site/content/applying_page_template/another_section/post.md new file mode 100644 index 0000000..e652160 --- /dev/null +++ b/test_site/content/applying_page_template/another_section/post.md @@ -0,0 +1,3 @@ ++++ +title = "Changed recursively" ++++ diff --git a/test_site/content/applying_page_template/from-section-config.md b/test_site/content/applying_page_template/from-section-config.md new file mode 100644 index 0000000..c95dd23 --- /dev/null +++ b/test_site/content/applying_page_template/from-section-config.md @@ -0,0 +1,4 @@ ++++ +weight = 0 +title = "From section config" ++++ diff --git a/test_site/content/applying_page_template/override.md b/test_site/content/applying_page_template/override.md new file mode 100644 index 0000000..f8f428b --- /dev/null +++ b/test_site/content/applying_page_template/override.md @@ -0,0 +1,5 @@ ++++ +template = "page_template_override.html" +weight = 1 +title = "Override" ++++ diff --git a/test_site/templates/page_template.html b/test_site/templates/page_template.html new file mode 100644 index 0000000..1633bb7 --- /dev/null +++ b/test_site/templates/page_template.html @@ -0,0 +1,7 @@ +{% extends "index.html" %} +{% block content %} +

Another page template, specified with the "page_template" key in the front matter

+ {{ page.content | safe }} + {% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %} + {% if page.later %}Next article: {{ page.later.permalink }}{% endif %} +{% endblock content %} diff --git a/test_site/templates/page_template_override.html b/test_site/templates/page_template_override.html new file mode 100644 index 0000000..549e31c --- /dev/null +++ b/test_site/templates/page_template_override.html @@ -0,0 +1,7 @@ +{% extends "index.html" %} +{% block content %} + {{ page.content | safe }} +

Yet another page template, using the override feature for page templates

+ {% if page.earlier %}Previous article: {{ page.earlier.permalink }}{% endif %} + {% if page.later %}Next article: {{ page.later.permalink }}{% endif %} +{% endblock content %}