mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
FIX: honor day, month, year etc when creating a note via calendar!
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
# Backlog
|
# Backlog
|
||||||
|
|
||||||
- vimhelp
|
- [ ] vimhelp
|
||||||
- yt video
|
- [ ] yt video
|
||||||
|
|
||||||
## Dones
|
## Dones
|
||||||
|
- [x] Honor day, month, year etc when creating a note via calendar!
|
||||||
- [x] awesome calendar support
|
- [x] awesome calendar support
|
||||||
- [x] maybe choose template in create note:
|
- [x] maybe choose template in create note:
|
||||||
- `new_templated_note()` first asks for title, then brings up a telescope picker of all template files in new `ZkCfg.template_dir`.
|
- `new_templated_note()` first asks for title, then brings up a telescope picker of all template files in new `ZkCfg.template_dir`.
|
||||||
|
|||||||
@@ -61,12 +61,28 @@ local function daysuffix(day)
|
|||||||
return 'th'
|
return 'th'
|
||||||
end
|
end
|
||||||
|
|
||||||
local function linesubst(line, title)
|
local daymap = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }
|
||||||
|
local monthmap = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }
|
||||||
|
|
||||||
|
local calenderinfo_today = function()
|
||||||
|
local dinfo = os.date("*t")
|
||||||
|
local opts = {}
|
||||||
|
opts.date = os.date("%Y-%m-%d")
|
||||||
|
opts.hdate = daymap[dinfo.wday] .. ', ' .. monthmap[dinfo.month] .. ' ' .. dinfo.day .. daysuffix(dinfo.day) .. ', ' .. dinfo.year
|
||||||
|
opts.week = os.date("%V")
|
||||||
|
opts.month = dinfo.month
|
||||||
|
opts.year = dinfo.year
|
||||||
|
opts.day = dinfo.day
|
||||||
|
return opts
|
||||||
|
end
|
||||||
|
|
||||||
|
local function linesubst(line, title, calendar_info)
|
||||||
|
local cinfo = calendar_info or calenderinfo_today()
|
||||||
local substs = {
|
local substs = {
|
||||||
date = os.date('%Y-%m-%d'),
|
date = cinfo.date,
|
||||||
hdate = os.date('%A, %B %dx, %Y'):gsub('x', daysuffix(os.date('%d'))),
|
hdate = cinfo.hdate,
|
||||||
week = os.date('%V'),
|
week = cinfo.week,
|
||||||
year = os.date('%Y'),
|
year = cinfo.year,
|
||||||
title = title,
|
title = title,
|
||||||
}
|
}
|
||||||
for k, v in pairs(substs) do
|
for k, v in pairs(substs) do
|
||||||
@@ -76,7 +92,7 @@ local function linesubst(line, title)
|
|||||||
return line
|
return line
|
||||||
end
|
end
|
||||||
|
|
||||||
local create_note_from_template = function (title, filepath, templatefn)
|
local create_note_from_template = function (title, filepath, templatefn, calendar_info)
|
||||||
-- first, read the template file
|
-- first, read the template file
|
||||||
local lines = {}
|
local lines = {}
|
||||||
for line in io.lines(templatefn) do
|
for line in io.lines(templatefn) do
|
||||||
@@ -86,7 +102,7 @@ local create_note_from_template = function (title, filepath, templatefn)
|
|||||||
-- now write the output file, substituting vars line by line
|
-- now write the output file, substituting vars line by line
|
||||||
local ofile = io.open(filepath, 'a')
|
local ofile = io.open(filepath, 'a')
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
ofile:write(linesubst(line, title) .. '\n')
|
ofile:write(linesubst(line, title, calendar_info) .. '\n')
|
||||||
end
|
end
|
||||||
|
|
||||||
ofile:close()
|
ofile:close()
|
||||||
@@ -224,14 +240,16 @@ end
|
|||||||
--
|
--
|
||||||
-- find today's daily note and create it if necessary.
|
-- find today's daily note and create it if necessary.
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
GotoToday = function(opts)
|
GotoToday = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or calenderinfo_today()
|
||||||
local word = opts.today or os.date("%Y-%m-%d")
|
local word = opts.date or os.date("%Y-%m-%d")
|
||||||
|
|
||||||
local fname = ZkCfg.dailies .. '/' .. word .. ZkCfg.extension
|
local fname = ZkCfg.dailies .. '/' .. word .. ZkCfg.extension
|
||||||
local fexists = file_exists(fname)
|
local fexists = file_exists(fname)
|
||||||
if ((fexists ~= true) and ((opts.follow_creates_nonexisting == true) or ZkCfg.follow_creates_nonexisting == true)) then
|
if ((fexists ~= true) and ((opts.follow_creates_nonexisting == true) or ZkCfg.follow_creates_nonexisting == true)) then
|
||||||
create_note_from_template(word, fname, note_type_templates.daily)
|
create_note_from_template(word, fname, note_type_templates.daily, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
@@ -404,12 +422,16 @@ end
|
|||||||
-- action on enter on a specific day: preview in telescope, stay in calendar on cancel, open note in other window on accept
|
-- action on enter on a specific day: preview in telescope, stay in calendar on cancel, open note in other window on accept
|
||||||
CalendarAction = function(day, month, year, week, dir)
|
CalendarAction = function(day, month, year, week, dir)
|
||||||
-- lsp
|
-- lsp
|
||||||
week = week
|
|
||||||
dir = dir
|
dir = dir
|
||||||
|
|
||||||
local today = string.format('%04d-%02d-%02d', year, month, day)
|
local today = string.format('%04d-%02d-%02d', year, month, day)
|
||||||
local opts = {}
|
local opts = {}
|
||||||
opts.today = today
|
opts.date = today
|
||||||
|
opts.hdate = daymap[week] .. ', ' .. monthmap[tonumber(month)] .. ' ' .. day .. daysuffix(day) .. ', ' .. year
|
||||||
|
opts.week = 'n/a' -- TODO: calculate the week somehow
|
||||||
|
opts.month = month
|
||||||
|
opts.year = year
|
||||||
|
opts.day = day
|
||||||
opts.calendar = true
|
opts.calendar = true
|
||||||
GotoToday(opts)
|
GotoToday(opts)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user