Register all Tera global fns on change
This commit is contained in:
parent
f11cc6abb4
commit
5d7e0bb33e
|
@ -6,6 +6,8 @@
|
||||||
- `section.subsections` can now be sorted by a `weight` attribute on a section front-matter
|
- `section.subsections` can now be sorted by a `weight` attribute on a section front-matter
|
||||||
- Do nothing on directory adding/removal in livereload
|
- Do nothing on directory adding/removal in livereload
|
||||||
- Add back `draft` on pages that was wrongly removed
|
- 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)
|
## 0.1.3 (2017-08-31)
|
||||||
|
|
||||||
|
|
|
@ -242,15 +242,14 @@ impl Site {
|
||||||
self.populate_sections();
|
self.populate_sections();
|
||||||
self.populate_tags_and_categories();
|
self.populate_tags_and_categories();
|
||||||
|
|
||||||
self.tera.register_global_function("get_page", global_fns::make_get_page(&self.pages));
|
self.register_tera_global_fns();
|
||||||
self.tera.register_global_function("get_section", global_fns::make_get_section(&self.sections));
|
|
||||||
self.register_get_url_fn();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Separate fn as it can be called in the serve command
|
pub fn register_tera_global_fns(&mut self) {
|
||||||
pub fn register_get_url_fn(&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(
|
self.tera.register_global_function(
|
||||||
"get_url",
|
"get_url",
|
||||||
global_fns::make_get_url(self.permalinks.clone(), self.config.clone())
|
global_fns::make_get_url(self.permalinks.clone(), self.config.clone())
|
||||||
|
|
|
@ -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
|
// 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
|
// Deletion is something that doesn't happen all the time so we
|
||||||
// don't need to optimise it too much
|
// don't need to optimise it too much
|
||||||
return site.build();
|
return site.build();
|
||||||
|
@ -165,9 +165,9 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
site.register_get_url_fn();
|
|
||||||
// New section, only render that one
|
// New section, only render that one
|
||||||
site.populate_sections();
|
site.populate_sections();
|
||||||
|
site.register_tera_global_fns();
|
||||||
return site.render_section(&site.sections[path], true);
|
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)?;
|
let page = Page::from_file(path, &site.config)?;
|
||||||
match site.add_page(page, true)? {
|
match site.add_page(page, true)? {
|
||||||
Some(prev) => {
|
Some(prev) => {
|
||||||
site.register_get_url_fn();
|
site.register_tera_global_fns();
|
||||||
// Updating a page
|
// Updating a page
|
||||||
let current = site.pages[path].clone();
|
let current = site.pages[path].clone();
|
||||||
// Front matter didn't change, only content did
|
// Front matter didn't change, only content did
|
||||||
|
@ -216,10 +216,10 @@ pub fn after_content_change(site: &mut Site, path: &Path) -> Result<()> {
|
||||||
|
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
site.register_get_url_fn();
|
|
||||||
// It's a new page!
|
// It's a new page!
|
||||||
site.populate_sections();
|
site.populate_sections();
|
||||||
site.populate_tags_and_categories();
|
site.populate_tags_and_categories();
|
||||||
|
site.register_tera_global_fns();
|
||||||
// No need to optimise that yet, we can revisit if it becomes an issue
|
// No need to optimise that yet, we can revisit if it becomes an issue
|
||||||
site.build()?;
|
site.build()?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue