Skip to content

Commit e510d1e

Browse files
committed
WIP: play around with value subst for journals
This provides an oversimplified way to add dynamic values to the journal template when creating new daily notes.
1 parent aa61312 commit e510d1e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lua/neorg/modules/core/norg/journal/module.lua

+25-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ require("neorg.modules.base")
2525
local module = neorg.modules.create("core.norg.journal")
2626
local log = require("neorg.external.log")
2727

28+
29+
--- Preform substitutions for a template file.
30+
--- Right now this just supports {DATE} and {FULLDATE}
31+
--- @param filename string #The filename to the template file that will have substitutions
32+
local function sub_file(filename)
33+
local lines = {}
34+
for line in io.lines(filename) do
35+
lines[#lines+1] = (line:gsub("%S+", function(word)
36+
if word:match("{DATE}") then
37+
return os.date("%Y-%m-%d")
38+
elseif word:match("{FULLDATE}") then
39+
return os.date("%A, %B %d, %Y")
40+
else
41+
return word
42+
end
43+
end))
44+
end
45+
return lines
46+
end
47+
2848
module.examples = {
2949
["Changing TOC format to divide year in quarters"] = function()
3050
-- In your ["core.norg.journal"] options, change toc_format to a function like this:
@@ -147,7 +167,11 @@ module.private = {
147167
workspace_path .. "/" .. folder_name .. "/" .. template_name
148168
)
149169
then
150-
vim.cmd("0read " .. workspace_path .. "/" .. folder_name .. "/" .. template_name .. "| w")
170+
--vim.cmd("0read " .. workspace_path .. "/" .. folder_name .. "/" .. template_name .. "| w")
171+
vim.api.nvim_put(sub_file(workspace_path .. "/" .. folder_name .. "/" .. template_name),
172+
"c",
173+
false,
174+
true)
151175
end
152176
end,
153177

0 commit comments

Comments
 (0)