From 1f1fc3f4546cd91bc999d287487dc2f0cc655fe9 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Thu, 29 Jun 2017 21:14:08 +0900 Subject: [PATCH] Remove section from page context --- CHANGELOG.md | 2 ++ src/bin/rebuild.rs | 4 ++-- src/content/page.rs | 5 ++--- src/site.rs | 8 ++++---- test_site/templates/page.html | 1 - tests/site.rs | 3 --- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cdc3fc5..49c2a555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 0.0.8 (unreleased) - Parallelize all the things +- Remove `section` from the `page` rendering context: this is too expensive. Use +the global function `get_section` if you need to get it ## 0.0.7 (2017-06-19) diff --git a/src/bin/rebuild.rs b/src/bin/rebuild.rs index ecebc55b..7ae3945b 100644 --- a/src/bin/rebuild.rs +++ b/src/bin/rebuild.rs @@ -176,7 +176,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> { // Front matter didn't change, only content did // so we render only the section page, not its content if current.meta == prev.meta { - return site.render_page(¤t, find_parent_section(site, ¤t)); + return site.render_page(¤t); } // Front matter changed @@ -201,7 +201,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> { site.render_index()?; }, PageChangesNeeded::Render => { - site.render_page(&site.pages[path], find_parent_section(site, ¤t))?; + site.render_page(&site.pages[path])?; }, }; } diff --git a/src/content/page.rs b/src/content/page.rs index 0f47ffde..dcfcc7aa 100644 --- a/src/content/page.rs +++ b/src/content/page.rs @@ -16,7 +16,7 @@ use rendering::context::Context; use fs::{read_file}; use content::utils::{find_related_assets, get_reading_analytics}; use content::file_info::FileInfo; -use content::{Header, Section}; +use content::{Header}; #[derive(Clone, Debug, PartialEq)] @@ -136,7 +136,7 @@ impl Page { } /// Renders the page using the default layout, unless specified in front-matter - pub fn render_html(&self, tera: &Tera, config: &Config, section: Option<&Section>) -> Result { + pub fn render_html(&self, tera: &Tera, config: &Config) -> Result { let tpl_name = match self.meta.template { Some(ref l) => l.to_string(), None => "page.html".to_string() @@ -147,7 +147,6 @@ impl Page { context.add("page", self); context.add("current_url", &self.permalink); context.add("current_path", &self.path); - context.add("section", §ion); tera.render(&tpl_name, &context) .chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) diff --git a/src/site.rs b/src/site.rs index 4ed55165..362c5561 100644 --- a/src/site.rs +++ b/src/site.rs @@ -348,7 +348,7 @@ impl Site { } /// Renders a single content page - pub fn render_page(&self, page: &Page, section: Option<&Section>) -> Result<()> { + pub fn render_page(&self, page: &Page) -> Result<()> { ensure_directory_exists(&self.output_path)?; // Copy the nesting of the content directory if we have sections for that page @@ -366,7 +366,7 @@ impl Site { create_directory(¤t_path)?; // Finally, create a index.html file there with the page rendered - let output = page.render_html(&self.tera, &self.config, section)?; + let output = page.render_html(&self.tera, &self.config)?; create_file(¤t_path.join("index.html"), &self.inject_livereload(output))?; // Copy any asset we found previously into the same directory as the index.html @@ -571,7 +571,7 @@ impl Site { section .pages .par_iter() - .map(|p| self.render_page(&p, Some(section))) + .map(|p| self.render_page(&p)) .fold(|| Ok(()), Result::and) .reduce(|| Ok(()), Result::and)?; } @@ -614,7 +614,7 @@ impl Site { ensure_directory_exists(&self.output_path)?; for page in self.get_all_orphan_pages() { - self.render_page(page, None)?; + self.render_page(page)?; } Ok(()) diff --git a/test_site/templates/page.html b/test_site/templates/page.html index 25bdbf89..25e0455d 100644 --- a/test_site/templates/page.html +++ b/test_site/templates/page.html @@ -1,7 +1,6 @@ {% extends "index.html" %} {% block content %} - {% if section %}Section:{{ section.permalink }}{% endif %} {{ page.content | safe }} {% if page.previous %}Previous article: {{ page.previous.permalink }}{% endif %} diff --git a/tests/site.rs b/tests/site.rs index d247fd5a..feaf8ced 100644 --- a/tests/site.rs +++ b/tests/site.rs @@ -132,9 +132,6 @@ fn can_build_site_without_live_reload() { // Both pages and sections are in the sitemap assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/posts/simple/")); assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/posts/")); - - // section is in the page context - assert!(file_contains!(public, "posts/python/index.html", "Section:")); } #[test]