From f30f28037928be75405a84addd9a9bd3242ee15e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 8 Apr 2021 09:33:35 +0300 Subject: feat: add a timestamp to the default template --- jt.md | 1 + src/journal.rs | 9 ++++++++- src/template.rs | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) 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", ¤t_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 = 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. "#; -- cgit v1.2.1