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)
|
||||
}
|
||||
|
||||
14
src/main.rs
14
src/main.rs
@@ -181,14 +181,24 @@ struct Args {
|
||||
|
||||
/// Resolve all wiki links in the given page, output the modified text
|
||||
#[arg(long)]
|
||||
resolve_links: Option<String>
|
||||
resolve_links: Option<String>,
|
||||
|
||||
/// Path to templates
|
||||
#[arg(long)]
|
||||
template_path: Option<String>
|
||||
}
|
||||
|
||||
#[rocket::main]
|
||||
async fn main() {
|
||||
let args = Args::parse();
|
||||
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);
|
||||
|
||||
if let Some(resolve_link) = args.resolve_link {
|
||||
|
||||
Reference in New Issue
Block a user