Remove section from page context

This commit is contained in:
Vincent Prouillet 2017-06-29 21:14:08 +09:00
parent c7bea0bc54
commit 1f1fc3f454
6 changed files with 10 additions and 13 deletions

View file

@ -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)

View file

@ -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(&current, find_parent_section(site, &current));
return site.render_page(&current);
}
// 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, &current))?;
site.render_page(&site.pages[path])?;
},
};
}

View file

@ -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<String> {
pub fn render_html(&self, tera: &Tera, config: &Config) -> Result<String> {
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", &section);
tera.render(&tpl_name, &context)
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display()))

View file

@ -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(&current_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(&current_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(())

View file

@ -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 %}

View file

@ -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", "<loc>https://replace-this-with-your-url.com/posts/simple/</loc>"));
assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/posts/</loc>"));
// section is in the page context
assert!(file_contains!(public, "posts/python/index.html", "Section:"));
}
#[test]