Fix XML template overriding

This commit is contained in:
Vincent Prouillet 2017-04-28 16:18:18 +09:00
parent 74be6d9c15
commit dd9bab3142
3 changed files with 14 additions and 4 deletions

View file

@ -1,6 +1,11 @@
# Changelog # Changelog
## 0.0.5 (unreleased)
- Fix XML templates overriding and reloading
## 0.0.4 (2017-04-23) ## 0.0.4 (2017-04-23)
- Fix RSS feed link and description - Fix RSS feed link and description
- Renamed `Page::url` and `Section::url` to `Page::path` and `Section::path` - Renamed `Page::url` and `Section::url` to `Page::path` and `Section::path`
- Pass `current_url` and `current_path` to every template - Pass `current_url` and `current_path` to every template
@ -14,6 +19,7 @@
- Only load templates ending by `.html` - Only load templates ending by `.html`
## 0.0.3 (2017-04-05) ## 0.0.3 (2017-04-05)
- Add some colours in console - Add some colours in console
- Allow using a file other than config.toml for config - Allow using a file other than config.toml for config
- Add sections to the index page context - Add sections to the index page context

View file

@ -131,7 +131,7 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
(ChangeKind::Templates, _) => { (ChangeKind::Templates, _) => {
console::info(&format!("-> Template changed {}", path.display())); console::info(&format!("-> Template changed {}", path.display()));
// Force refresh // Force refresh
rebuild_done_handling(&broadcaster, site.rebuild_after_template_change(), "/x.js"); rebuild_done_handling(&broadcaster, site.rebuild_after_template_change(&path), "/x.js");
}, },
(ChangeKind::StaticFiles, p) => { (ChangeKind::StaticFiles, p) => {
if path.is_file() { if path.is_file() {

View file

@ -80,7 +80,7 @@ impl Site {
pub fn new<P: AsRef<Path>>(path: P, config_file: &str) -> Result<Site> { pub fn new<P: AsRef<Path>>(path: P, config_file: &str) -> Result<Site> {
let path = path.as_ref(); let path = path.as_ref();
let tpl_glob = format!("{}/{}", path.to_string_lossy().replace("\\", "/"), "templates/**/*.html"); let tpl_glob = format!("{}/{}", path.to_string_lossy().replace("\\", "/"), "templates/**/*.*ml");
let mut tera = Tera::new(&tpl_glob).chain_err(|| "Error parsing templates")?; let mut tera = Tera::new(&tpl_glob).chain_err(|| "Error parsing templates")?;
tera.extend(&GUTENBERG_TERA)?; tera.extend(&GUTENBERG_TERA)?;
tera.register_filter("markdown", filters::markdown); tera.register_filter("markdown", filters::markdown);
@ -307,9 +307,13 @@ impl Site {
self.build() self.build()
} }
pub fn rebuild_after_template_change(&mut self) -> Result<()> { pub fn rebuild_after_template_change(&mut self, path: &Path) -> Result<()> {
self.tera.full_reload()?; self.tera.full_reload()?;
self.build_pages() match path.file_name().unwrap().to_str().unwrap() {
"sitemap.xml" => self.render_sitemap(),
"rss.xml" => self.render_rss_feed(),
_ => self.build_pages()
}
} }
pub fn build_pages(&self) -> Result<()> { pub fn build_pages(&self) -> Result<()> {