From 9607498d3ee2fb012ad526d21cb5d489787ab0d0 Mon Sep 17 00:00:00 2001 From: Ahmed Magdy Date: Sat, 14 Dec 2024 16:35:10 +0100 Subject: [PATCH] feature: allow grouping daily notes by date. --- lua/obsidian/client.lua | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua index ff6e500c..be8c0669 100644 --- a/lua/obsidian/client.lua +++ b/lua/obsidian/client.lua @@ -117,7 +117,14 @@ Client.set_workspace = function(self, workspace, opts) end if self.opts.daily_notes.folder ~= nil then - local daily_notes_subdir = self.dir / self.opts.daily_notes.folder + ---@type string + local folder = self.opts.daily_notes.folder + + ---@diagnostic disable-next-line: need-check-nil + if folder:find "%%" then + folder = tostring(os.date(folder, os.time())) + end + local daily_notes_subdir = self.dir / folder daily_notes_subdir:mkdir { parents = true, exists_ok = true } end @@ -1914,9 +1921,16 @@ Client.daily_note_path = function(self, datetime) local path = Path:new(self.dir) if self.opts.daily_notes.folder ~= nil then - ---@type obsidian.Path + ---@type string + local folder = self.opts.daily_notes.folder + + ---@diagnostic disable-next-line: need-check-nil + if folder:find "%%" then + folder = tostring(os.date(folder, datetime)) + end + ---@diagnostic disable-next-line: assign-type-mismatch - path = path / self.opts.daily_notes.folder + path = path / folder elseif self.opts.notes_subdir ~= nil then ---@type obsidian.Path ---@diagnostic disable-next-line: assign-type-mismatch