Browse Source

Fewer string cloning for tpl names

index-subcmd
Vincent Prouillet 6 years ago
parent
commit
9c2eeaf1f7
2 changed files with 10 additions and 9 deletions
  1. +5
    -5
      components/library/src/content/section.rs
  2. +5
    -4
      components/library/src/pagination/mod.rs

+ 5
- 5
components/library/src/content/section.rs View File

@@ -128,14 +128,14 @@ impl Section {
Ok(section) Ok(section)
} }


pub fn get_template_name(&self) -> String {
pub fn get_template_name(&self) -> &str {
match self.meta.template { match self.meta.template {
Some(ref l) => l.to_string(),
Some(ref l) => l,
None => { None => {
if self.is_index() { if self.is_index() {
return "index.html".to_string();
return "index.html"
} }
"section.html".to_string()
"section.html"
} }
} }
} }
@@ -175,7 +175,7 @@ impl Section {
context.insert("current_path", &self.path); context.insert("current_path", &self.path);
context.insert("section", &self.to_serialized(library)); context.insert("section", &self.to_serialized(library));


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()))
} }




+ 5
- 4
components/library/src/pagination/mod.rs View File

@@ -55,6 +55,7 @@ pub struct Paginator<'a> {
pub permalink: String, pub permalink: String,
path: String, path: String,
pub paginate_path: String, pub paginate_path: String,
template: String,
/// Whether this is the index section, we need it for the template name /// Whether this is the index section, we need it for the template name
is_index: bool, is_index: bool,
} }
@@ -73,6 +74,7 @@ impl<'a> Paginator<'a> {
path: section.path.clone(), path: section.path.clone(),
paginate_path: section.meta.paginate_path.clone(), paginate_path: section.meta.paginate_path.clone(),
is_index: section.is_index(), is_index: section.is_index(),
template: section.get_template_name().to_string(),
}; };


paginator.fill_pagers(library); paginator.fill_pagers(library);
@@ -100,6 +102,7 @@ impl<'a> Paginator<'a> {
.clone() .clone()
.unwrap_or_else(|| "pages".to_string()), .unwrap_or_else(|| "pages".to_string()),
is_index: false, is_index: false,
template: format!("{}/single.html", taxonomy.kind.name),
}; };


paginator.fill_pagers(library); paginator.fill_pagers(library);
@@ -204,22 +207,20 @@ impl<'a> Paginator<'a> {
) -> Result<String> { ) -> Result<String> {
let mut context = Context::new(); let mut context = Context::new();
context.insert("config", &config); context.insert("config", &config);
let template_name = match self.root {
match self.root {
PaginationRoot::Section(s) => { PaginationRoot::Section(s) => {
context context
.insert("section", &SerializingSection::from_section_basic(s, Some(library))); .insert("section", &SerializingSection::from_section_basic(s, Some(library)));
s.get_template_name()
} }
PaginationRoot::Taxonomy(t) => { PaginationRoot::Taxonomy(t) => {
context.insert("taxonomy", &t.kind); context.insert("taxonomy", &t.kind);
format!("{}/single.html", t.kind.name)
} }
}; };
context.insert("current_url", &pager.permalink); context.insert("current_url", &pager.permalink);
context.insert("current_path", &pager.path); context.insert("current_path", &pager.path);
context.insert("paginator", &self.build_paginator_context(pager)); context.insert("paginator", &self.build_paginator_context(pager));


render_template(&template_name, tera, &context, &config.theme)
render_template(&self.template, tera, &context, &config.theme)
.chain_err(|| format!("Failed to render pager {}", pager.index)) .chain_err(|| format!("Failed to render pager {}", pager.index))
} }
} }


Loading…
Cancel
Save