diff options
Diffstat (limited to 'src/template.rs')
-rw-r--r-- | src/template.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/template.rs b/src/template.rs index 89c1a15..23b9b06 100644 --- a/src/template.rs +++ b/src/template.rs @@ -4,10 +4,22 @@ use tera::{Context, Tera}; const NEW_ENTRY: &str = r#"[[!meta title="{{ title }}"]] [[!meta date="{{ date }}"]] +{% if topic %} +[[!meta link="{{ topic }}"]] +{% endif %} This is the default template. "#; +const NEW_TOPIC: &str = r#"[[!meta title="{{ title }}"]] + +This is the default topic template. + +# Entries + +[[!inline pages="link(.)" archive=yes reverse=yes trail=yes]] +"#; + pub struct Templates { tera: Tera, } @@ -17,6 +29,7 @@ impl Templates { let glob = format!("{}/.config/templates/*", dirname.display()); let mut tera = Tera::new(&glob).expect("Tera::new"); add_default_template(&mut tera, "new_entry", NEW_ENTRY); + add_default_template(&mut tera, "new_topic", NEW_TOPIC); Ok(Self { tera }) } @@ -24,6 +37,10 @@ impl Templates { self.render("new_entry", &context) } + pub fn new_topic(&self, context: &Context) -> Result<String, JournalError> { + self.render("new_topic", &context) + } + fn render(&self, name: &str, context: &Context) -> Result<String, JournalError> { match self.tera.render(name, &context) { Ok(s) => Ok(s), |