From 2a033de001efff7d1a6b31cc27b6a8f0e6d9b759 Mon Sep 17 00:00:00 2001 From: Gambhiro Date: Wed, 11 Jan 2017 21:09:22 +0000 Subject: [PATCH] look in different paths for page template --- src/renderer/html_handlebars/hbs_renderer.rs | 25 ++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 055671fa..a32e3207 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -131,10 +131,27 @@ impl Renderer for HtmlHandlebars { // Render the chapters of each book for (key, book) in &book_project.translations { - // Read in the page template - let tmpl_path: &PathBuf = &book_project.get_template_dir().join("_layouts").join("page.hbs"); - let s = if tmpl_path.exists() { - try!(utils::fs::file_to_string(&tmpl_path)) + // Look for the page template in these paths + let mut tmpl_paths: Vec = vec![]; + + // default scheme: assets/_html-template/_layouts/page.hbs + tmpl_paths.push(book_project.get_template_dir().join("_layouts").join("page.hbs")); + // maybe the user doesn't use _layouts folder: assets/_html-template/page.hbs + tmpl_paths.push(book_project.get_template_dir().join("page.hbs")); + // also look for index.hbs which was the template name in v0.0.15 + tmpl_paths.push(book_project.get_template_dir().join("index.hbs")); + + let first_path_that_exists = |paths: &Vec| -> Option { + for p in paths.iter() { + if p.exists() { + return Some(PathBuf::from(p)); + } + } + None + }; + + let s = if let Some(p) = first_path_that_exists(&tmpl_paths) { + try!(utils::fs::file_to_string(&p)) } else { try!(utils::fs::get_data_file("data/_html-template/_layouts/page.hbs")) };