Browse Source

Register all Tera global fns on change

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
5d7e0bb33e
3 changed files with 10 additions and 9 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +4
    -5
      components/site/src/lib.rs
  3. +4
    -4
      src/rebuild.rs

+ 2
- 0
CHANGELOG.md View File

@@ -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)




+ 4
- 5
components/site/src/lib.rs View File

@@ -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.tera.register_global_function("get_section", global_fns::make_get_section(&self.sections));
self.register_get_url_fn();
self.register_tera_global_fns();


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


+ 4
- 4
src/rebuild.rs 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 // 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…
Cancel
Save