Update deps and fix deprecrations

This commit is contained in:
Vincent Prouillet 2018-09-09 19:43:14 +02:00
parent 8cf7dc7cce
commit 38b30eb144
10 changed files with 278 additions and 246 deletions

View file

@ -3,6 +3,7 @@
## 0.4.3 (unreleased) ## 0.4.3 (unreleased)
- Gutenberg has changed name to REPLACE_ME! - Gutenberg has changed name to REPLACE_ME!
- Update dependencies, fixing a few bugs with templates
## 0.4.2 (2018-09-03) ## 0.4.2 (2018-09-03)

447
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -183,7 +183,7 @@ impl Page {
anchor_insert, anchor_insert,
); );
context.tera_context.add("page", self); context.tera_context.insert("page", self);
let res = render_content(&self.raw_content, &context) let res = render_content(&self.raw_content, &context)
.chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?; .chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?;
@ -203,10 +203,10 @@ impl Page {
}; };
let mut context = TeraContext::new(); let mut context = TeraContext::new();
context.add("config", config); context.insert("config", config);
context.add("page", self); context.insert("page", self);
context.add("current_url", &self.permalink); context.insert("current_url", &self.permalink);
context.add("current_path", &self.path); context.insert("current_path", &self.path);
render_template(&tpl_name, tera, &context, &config.theme) render_template(&tpl_name, tera, &context, &config.theme)
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) .chain_err(|| format!("Failed to render page '{}'", self.file.path.display()))

View file

@ -133,7 +133,7 @@ impl Section {
self.meta.insert_anchor_links, self.meta.insert_anchor_links,
); );
context.tera_context.add("section", self); context.tera_context.insert("section", self);
let res = render_content(&self.raw_content, &context) let res = render_content(&self.raw_content, &context)
.chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?; .chain_err(|| format!("Failed to render content of {}", self.file.path.display()))?;
@ -147,10 +147,10 @@ impl Section {
let tpl_name = self.get_template_name(); let tpl_name = self.get_template_name();
let mut context = TeraContext::new(); let mut context = TeraContext::new();
context.add("config", config); context.insert("config", config);
context.add("section", self); context.insert("section", self);
context.add("current_url", &self.permalink); context.insert("current_url", &self.permalink);
context.add("current_path", &self.path); context.insert("current_path", &self.path);
render_template(&tpl_name, tera, &context, &config.theme) render_template(&tpl_name, tera, &context, &config.theme)
.chain_err(|| format!("Failed to render section '{}'", self.file.path.display())) .chain_err(|| format!("Failed to render section '{}'", self.file.path.display()))

View file

@ -212,20 +212,20 @@ impl<'a> Paginator<'a> {
pub fn render_pager(&self, pager: &Pager, config: &Config, tera: &Tera) -> Result<String> { pub fn render_pager(&self, pager: &Pager, config: &Config, tera: &Tera) -> Result<String> {
let mut context = Context::new(); let mut context = Context::new();
context.add("config", &config); context.insert("config", &config);
let template_name = match self.root { let template_name = match self.root {
PaginationRoot::Section(s) => { PaginationRoot::Section(s) => {
context.add("section", &s); context.insert("section", &s);
s.get_template_name() s.get_template_name()
} }
PaginationRoot::Taxonomy(t) => { PaginationRoot::Taxonomy(t) => {
context.add("taxonomy", &t.kind); context.insert("taxonomy", &t.kind);
format!("{}/single.html", t.kind.name) format!("{}/single.html", t.kind.name)
} }
}; };
context.add("current_url", &pager.permalink); context.insert("current_url", &pager.permalink);
context.add("current_path", &pager.path); context.insert("current_path", &pager.path);
context.add("paginator", &self.build_paginator_context(pager)); context.insert("paginator", &self.build_paginator_context(pager));
render_template(&template_name, tera, &context, &config.theme) render_template(&template_name, tera, &context, &config.theme)
.chain_err(|| format!("Failed to render pager {}", pager.index)) .chain_err(|| format!("Failed to render pager {}", pager.index))

View file

@ -51,7 +51,7 @@ impl TempHeader {
pub fn to_string(&self, tera: &Tera, insert_anchor: InsertAnchor) -> String { pub fn to_string(&self, tera: &Tera, insert_anchor: InsertAnchor) -> String {
let anchor_link = if insert_anchor != InsertAnchor::None { let anchor_link = if insert_anchor != InsertAnchor::None {
let mut c = TeraContext::new(); let mut c = TeraContext::new();
c.add("id", &self.id); c.insert("id", &self.id);
tera.render("anchor-link.html", &c).unwrap() tera.render("anchor-link.html", &c).unwrap()
} else { } else {
String::new() String::new()

View file

@ -739,14 +739,14 @@ impl Site {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
pages.sort_by(|a, b| a.permalink.cmp(&b.permalink)); pages.sort_by(|a, b| a.permalink.cmp(&b.permalink));
context.add("pages", &pages); context.insert("pages", &pages);
let mut sections = self.sections let mut sections = self.sections
.values() .values()
.map(|s| SitemapEntry::new(s.permalink.clone(), None)) .map(|s| SitemapEntry::new(s.permalink.clone(), None))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
sections.sort_by(|a, b| a.permalink.cmp(&b.permalink)); sections.sort_by(|a, b| a.permalink.cmp(&b.permalink));
context.add("sections", &sections); context.insert("sections", &sections);
let mut taxonomies = vec![]; let mut taxonomies = vec![];
for taxonomy in &self.taxonomies { for taxonomy in &self.taxonomies {
@ -759,9 +759,9 @@ impl Site {
terms.sort_by(|a, b| a.permalink.cmp(&b.permalink)); terms.sort_by(|a, b| a.permalink.cmp(&b.permalink));
taxonomies.push(terms); taxonomies.push(terms);
} }
context.add("taxonomies", &taxonomies); context.insert("taxonomies", &taxonomies);
context.add("config", &self.config); context.insert("config", &self.config);
let sitemap = &render_template("sitemap.xml", &self.tera, &context, &self.config.theme)?; let sitemap = &render_template("sitemap.xml", &self.tera, &context, &self.config.theme)?;
@ -791,10 +791,10 @@ impl Site {
} }
let (sorted_pages, _) = sort_pages(pages, SortBy::Date); let (sorted_pages, _) = sort_pages(pages, SortBy::Date);
context.add("last_build_date", &sorted_pages[0].meta.date.clone().map(|d| d.to_string())); context.insert("last_build_date", &sorted_pages[0].meta.date.clone().map(|d| d.to_string()));
// limit to the last n elements // limit to the last n elements
context.add("pages", &sorted_pages.iter().take(self.config.rss_limit).collect::<Vec<_>>()); context.insert("pages", &sorted_pages.iter().take(self.config.rss_limit).collect::<Vec<_>>());
context.add("config", &self.config); context.insert("config", &self.config);
let rss_feed_url = if let Some(ref base) = base_path { let rss_feed_url = if let Some(ref base) = base_path {
self.config.make_permalink(&base.join("rss.xml").to_string_lossy().replace('\\', "/")) self.config.make_permalink(&base.join("rss.xml").to_string_lossy().replace('\\', "/"))
@ -802,7 +802,7 @@ impl Site {
self.config.make_permalink("rss.xml") self.config.make_permalink("rss.xml")
}; };
context.add("feed_url", &rss_feed_url); context.insert("feed_url", &rss_feed_url);
let feed = &render_template("rss.xml", &self.tera, &context, &self.config.theme)?; let feed = &render_template("rss.xml", &self.tera, &context, &self.config.theme)?;

View file

@ -88,11 +88,11 @@ impl Taxonomy {
pub fn render_term(&self, item: &TaxonomyItem, tera: &Tera, config: &Config) -> Result<String> { pub fn render_term(&self, item: &TaxonomyItem, tera: &Tera, config: &Config) -> Result<String> {
let mut context = Context::new(); let mut context = Context::new();
context.add("config", config); context.insert("config", config);
context.add("term", item); context.insert("term", item);
context.add("taxonomy", &self.kind); context.insert("taxonomy", &self.kind);
context.add("current_url", &config.make_permalink(&format!("{}/{}", self.kind.name, item.slug))); context.insert("current_url", &config.make_permalink(&format!("{}/{}", self.kind.name, item.slug)));
context.add("current_path", &format!("/{}/{}", self.kind.name, item.slug)); context.insert("current_path", &format!("/{}/{}", self.kind.name, item.slug));
render_template(&format!("{}/single.html", self.kind.name), tera, &context, &config.theme) render_template(&format!("{}/single.html", self.kind.name), tera, &context, &config.theme)
.chain_err(|| format!("Failed to render single term {} page.", self.kind.name)) .chain_err(|| format!("Failed to render single term {} page.", self.kind.name))
@ -100,11 +100,11 @@ impl Taxonomy {
pub fn render_all_terms(&self, tera: &Tera, config: &Config) -> Result<String> { pub fn render_all_terms(&self, tera: &Tera, config: &Config) -> Result<String> {
let mut context = Context::new(); let mut context = Context::new();
context.add("config", config); context.insert("config", config);
context.add("terms", &self.items); context.insert("terms", &self.items);
context.add("taxonomy", &self.kind); context.insert("taxonomy", &self.kind);
context.add("current_url", &config.make_permalink(&self.kind.name)); context.insert("current_url", &config.make_permalink(&self.kind.name));
context.add("current_path", &self.kind.name); context.insert("current_path", &self.kind.name);
render_template(&format!("{}/list.html", self.kind.name), tera, &context, &config.theme) render_template(&format!("{}/list.html", self.kind.name), tera, &context, &config.theme)
.chain_err(|| format!("Failed to render a list of {} page.", self.kind.name)) .chain_err(|| format!("Failed to render a list of {} page.", self.kind.name))

View file

@ -48,7 +48,7 @@ lazy_static! {
/// via refresh to the url given /// via refresh to the url given
pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> { pub fn render_redirect_template(url: &str, tera: &Tera) -> Result<String> {
let mut context = Context::new(); let mut context = Context::new();
context.add("url", &url); context.insert("url", &url);
tera.render("internal/alias.html", &context) tera.render("internal/alias.html", &context)
.chain_err(|| format!("Failed to render alias for '{}'", url)) .chain_err(|| format!("Failed to render alias for '{}'", url))

View file

@ -9,8 +9,8 @@ macro_rules! render_default_tpl {
($filename: expr, $url: expr) => { ($filename: expr, $url: expr) => {
{ {
let mut context = Context::new(); let mut context = Context::new();
context.add("filename", $filename); context.insert("filename", $filename);
context.add("url", $url); context.insert("url", $url);
Tera::one_off(DEFAULT_TPL, &context, true).map_err(|e| e.into()) Tera::one_off(DEFAULT_TPL, &context, true).map_err(|e| e.into())
} }
}; };