Add support for custom template path.

This commit is contained in:
2024-09-27 05:03:02 -05:00
parent 9ae1022a21
commit 2198201713
2 changed files with 19 additions and 5 deletions

View File

@@ -289,10 +289,14 @@ fn render_markdown (content: &tera::Value, args: &HashMap<String, tera::Value>)
impl PageRenderer { impl PageRenderer {
pub fn new() -> 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); tera.register_filter("markdown", render_markdown);
PageRenderer { PageRenderer {
template_root: DEFAULT_TEMPLATES_PATH.into(), template_root: template_path.into(),
tera tera
} }
} }

View File

@@ -181,14 +181,24 @@ struct Args {
/// Resolve all wiki links in the given page, output the modified text /// Resolve all wiki links in the given page, output the modified text
#[arg(long)] #[arg(long)]
resolve_links: Option<String> resolve_links: Option<String>,
/// Path to templates
#[arg(long)]
template_path: Option<String>
} }
#[rocket::main] #[rocket::main]
async fn main() { async fn main() {
let args = Args::parse(); let args = Args::parse();
let historian = Historian::new(args.wiki_path); let historian = Historian::new(args.wiki_path);
let renderer = PageRenderer::new();
let renderer = if let Some(template_path) = args.template_path {
PageRenderer::with_template_path(&template_path)
} else {
PageRenderer::new()
};
let linker = Linker::new(&historian); let linker = Linker::new(&historian);
if let Some(resolve_link) = args.resolve_link { if let Some(resolve_link) = args.resolve_link {