diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cdc3fc..49c2a55 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 ecebc55..7ae3945 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 0f47ffd..dcfcc7a 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 4ed5516..362c556 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 25bdbf8..25e0455 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 d247fd5..feaf8ce 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]