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) ## 0.0.8 (unreleased)
- Parallelize all the things - 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) ## 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 // Front matter didn't change, only content did
// so we render only the section page, not its content // so we render only the section page, not its content
if current.meta == prev.meta { if current.meta == prev.meta {
return site.render_page(&current, find_parent_section(site, &current)); return site.render_page(&current);
} }
// Front matter changed // Front matter changed
@ -201,7 +201,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
site.render_index()?; site.render_index()?;
}, },
PageChangesNeeded::Render => { 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 fs::{read_file};
use content::utils::{find_related_assets, get_reading_analytics}; use content::utils::{find_related_assets, get_reading_analytics};
use content::file_info::FileInfo; use content::file_info::FileInfo;
use content::{Header, Section}; use content::{Header};
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
@ -136,7 +136,7 @@ impl Page {
} }
/// Renders the page using the default layout, unless specified in front-matter /// 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 { let tpl_name = match self.meta.template {
Some(ref l) => l.to_string(), Some(ref l) => l.to_string(),
None => "page.html".to_string() None => "page.html".to_string()
@ -147,7 +147,6 @@ impl Page {
context.add("page", self); context.add("page", self);
context.add("current_url", &self.permalink); context.add("current_url", &self.permalink);
context.add("current_path", &self.path); context.add("current_path", &self.path);
context.add("section", &section);
tera.render(&tpl_name, &context) tera.render(&tpl_name, &context)
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) .chain_err(|| format!("Failed to render page '{}'", self.file.path.display()))

View file

@ -348,7 +348,7 @@ impl Site {
} }
/// Renders a single content page /// 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)?; ensure_directory_exists(&self.output_path)?;
// Copy the nesting of the content directory if we have sections for that page // Copy the nesting of the content directory if we have sections for that page
@ -366,7 +366,7 @@ impl Site {
create_directory(&current_path)?; create_directory(&current_path)?;
// Finally, create a index.html file there with the page rendered // 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))?; 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 // Copy any asset we found previously into the same directory as the index.html
@ -571,7 +571,7 @@ impl Site {
section section
.pages .pages
.par_iter() .par_iter()
.map(|p| self.render_page(&p, Some(section))) .map(|p| self.render_page(&p))
.fold(|| Ok(()), Result::and) .fold(|| Ok(()), Result::and)
.reduce(|| Ok(()), Result::and)?; .reduce(|| Ok(()), Result::and)?;
} }
@ -614,7 +614,7 @@ impl Site {
ensure_directory_exists(&self.output_path)?; ensure_directory_exists(&self.output_path)?;
for page in self.get_all_orphan_pages() { for page in self.get_all_orphan_pages() {
self.render_page(page, None)?; self.render_page(page)?;
} }
Ok(()) Ok(())

View file

@ -1,7 +1,6 @@
{% extends "index.html" %} {% extends "index.html" %}
{% block content %} {% block content %}
{% if section %}Section:{{ section.permalink }}{% endif %}
{{ page.content | safe }} {{ page.content | safe }}
{% if page.previous %}Previous article: {{ page.previous.permalink }}{% endif %} {% 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 // 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/simple/</loc>"));
assert!(file_contains!(public, "sitemap.xml", "<loc>https://replace-this-with-your-url.com/posts/</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] #[test]