mirror of
https://github.com/getzola/zola
synced 2024-12-13 13:52:28 +00:00
Fewer string cloning for tpl names
This commit is contained in:
parent
1d97b24898
commit
9c2eeaf1f7
2 changed files with 10 additions and 9 deletions
|
@ -128,14 +128,14 @@ impl Section {
|
|||
Ok(section)
|
||||
}
|
||||
|
||||
pub fn get_template_name(&self) -> String {
|
||||
pub fn get_template_name(&self) -> &str {
|
||||
match self.meta.template {
|
||||
Some(ref l) => l.to_string(),
|
||||
Some(ref l) => l,
|
||||
None => {
|
||||
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("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()))
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ pub struct Paginator<'a> {
|
|||
pub permalink: String,
|
||||
path: String,
|
||||
pub paginate_path: String,
|
||||
template: String,
|
||||
/// Whether this is the index section, we need it for the template name
|
||||
is_index: bool,
|
||||
}
|
||||
|
@ -73,6 +74,7 @@ impl<'a> Paginator<'a> {
|
|||
path: section.path.clone(),
|
||||
paginate_path: section.meta.paginate_path.clone(),
|
||||
is_index: section.is_index(),
|
||||
template: section.get_template_name().to_string(),
|
||||
};
|
||||
|
||||
paginator.fill_pagers(library);
|
||||
|
@ -100,6 +102,7 @@ impl<'a> Paginator<'a> {
|
|||
.clone()
|
||||
.unwrap_or_else(|| "pages".to_string()),
|
||||
is_index: false,
|
||||
template: format!("{}/single.html", taxonomy.kind.name),
|
||||
};
|
||||
|
||||
paginator.fill_pagers(library);
|
||||
|
@ -204,22 +207,20 @@ impl<'a> Paginator<'a> {
|
|||
) -> Result<String> {
|
||||
let mut context = Context::new();
|
||||
context.insert("config", &config);
|
||||
let template_name = match self.root {
|
||||
match self.root {
|
||||
PaginationRoot::Section(s) => {
|
||||
context
|
||||
.insert("section", &SerializingSection::from_section_basic(s, Some(library)));
|
||||
s.get_template_name()
|
||||
}
|
||||
PaginationRoot::Taxonomy(t) => {
|
||||
context.insert("taxonomy", &t.kind);
|
||||
format!("{}/single.html", t.kind.name)
|
||||
}
|
||||
};
|
||||
context.insert("current_url", &pager.permalink);
|
||||
context.insert("current_path", &pager.path);
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue