Register all Tera global fns on change

This commit is contained in:
Vincent Prouillet 2017-09-26 17:25:55 +09:00
parent f11cc6abb4
commit 5d7e0bb33e
3 changed files with 10 additions and 9 deletions

View file

@ -6,6 +6,8 @@
- `section.subsections` can now be sorted by a `weight` attribute on a section front-matter
- Do nothing on directory adding/removal in livereload
- Add back `draft` on pages that was wrongly removed
- Page and Section `path` field is not starting with a `/` anymore
- All Tera global fns are now rebuilt on changes
## 0.1.3 (2017-08-31)

View file

@ -242,15 +242,14 @@ impl Site {
self.populate_sections();
self.populate_tags_and_categories();
self.tera.register_global_function("get_page", global_fns::make_get_page(&self.pages));
self.tera.register_global_function("get_section", global_fns::make_get_section(&self.sections));
self.register_get_url_fn();
self.register_tera_global_fns();
Ok(())
}
/// Separate fn as it can be called in the serve command
pub fn register_get_url_fn(&mut self) {
pub fn register_tera_global_fns(&mut self) {
self.tera.register_global_function("get_page", global_fns::make_get_page(&self.pages));
self.tera.register_global_function("get_section", global_fns::make_get_section(&self.sections));
self.tera.register_global_function(
"get_url",
global_fns::make_get_url(self.permalinks.clone(), self.config.clone())

View file

@ -129,7 +129,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
};
}
// Ensure we have our fn updated so it doesn't contain the permalinks deleted
site.register_get_url_fn();
site.register_tera_global_fns();
// Deletion is something that doesn't happen all the time so we
// don't need to optimise it too much
return site.build();
@ -165,9 +165,9 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
return Ok(());
},
None => {
site.register_get_url_fn();
// New section, only render that one
site.populate_sections();
site.register_tera_global_fns();
return site.render_section(&site.sections[path], true);
}
};
@ -177,7 +177,7 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
let page = Page::from_file(path, &site.config)?;
match site.add_page(page, true)? {
Some(prev) => {
site.register_get_url_fn();
site.register_tera_global_fns();
// Updating a page
let current = site.pages[path].clone();
// Front matter didn't change, only content did
@ -216,10 +216,10 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
},
None => {
site.register_get_url_fn();
// It's a new page!
site.populate_sections();
site.populate_tags_and_categories();
site.register_tera_global_fns();
// No need to optimise that yet, we can revisit if it becomes an issue
site.build()?;
}