summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-08 09:33:35 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-08 09:37:21 +0300
commitf30f28037928be75405a84addd9a9bd3242ee15e (patch)
tree9defe8213c416e8f48ba96ad7cf62acff3ffec5f
parentfc917bf829c8a7cbf950754abc7085ffb00dbf17 (diff)
downloadjt2-f30f28037928be75405a84addd9a9bd3242ee15e.tar.gz
feat: add a timestamp to the default template
-rw-r--r--jt.md1
-rw-r--r--src/journal.rs9
-rw-r--r--src/template.rs1
3 files changed, 10 insertions, 1 deletions
diff --git a/jt.md b/jt.md
index 1b80c5d..d1f3b14 100644
--- a/jt.md
+++ b/jt.md
@@ -155,6 +155,7 @@ when I run jt2 --editor=none --dirname=jrnl new "Abracadabra"
then command is successful
and there is one draft in jrnl
and draft 0 in jrnl contains "Abracadabra"
+and draft 0 in jrnl contains "!meta date="
given an executable script append.sh
when I run jt2 --editor=./append.sh --dirname=jrnl edit 0
diff --git a/src/journal.rs b/src/journal.rs
index e5a692e..788a34b 100644
--- a/src/journal.rs
+++ b/src/journal.rs
@@ -1,6 +1,6 @@
use crate::error::JournalError;
use crate::template::Templates;
-use chrono::Local;
+use chrono::{DateTime, Local};
use std::path::{Path, PathBuf};
use std::process::Command;
use tera::Context;
@@ -66,6 +66,7 @@ impl Journal {
let mut context = Context::new();
context.insert("title", title);
+ context.insert("date", &current_timestamp());
let pathname = self.pick_file_id(&drafts)?;
let text = self.templates.new_draft(&context)?;
@@ -151,3 +152,9 @@ fn is_dir(path: &Path) -> bool {
false
}
}
+
+fn current_timestamp() -> String {
+ let now = Local::now();
+ let now: DateTime<Local> = DateTime::from(now);
+ now.to_rfc2822()
+}
diff --git a/src/template.rs b/src/template.rs
index 1ad8a54..89c1a15 100644
--- a/src/template.rs
+++ b/src/template.rs
@@ -3,6 +3,7 @@ use std::path::Path;
use tera::{Context, Tera};
const NEW_ENTRY: &str = r#"[[!meta title="{{ title }}"]]
+[[!meta date="{{ date }}"]]
This is the default template.
"#;