Add support for custom template path.
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@@ -289,14 +289,18 @@ fn render_markdown (content: &tera::Value, args: &HashMap<String, tera::Value>)
|
||||
|
||||
impl PageRenderer {
|
||||
pub fn new() -> PageRenderer {
|
||||
let mut tera = tera::Tera::new("templates/**/*.html").unwrap();
|
||||
Self::with_template_path(DEFAULT_TEMPLATES_PATH)
|
||||
}
|
||||
|
||||
pub fn with_template_path(template_path: &str) -> PageRenderer {
|
||||
let mut tera = tera::Tera::new(&format!("{template_path}/**/*.html")).unwrap();
|
||||
tera.register_filter("markdown", render_markdown);
|
||||
PageRenderer {
|
||||
template_root: DEFAULT_TEMPLATES_PATH.into(),
|
||||
template_root: template_path.into(),
|
||||
tera
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn render_page(&self, historian: &Historian, page: &Page, options: &Table) -> String {
|
||||
self.render_page_template("page.html", &historian, &page, &options)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user