mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
weekly templates, findings, ...
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
# Backlog
|
||||
|
||||
- create new note dialog: choose template
|
||||
- [ ] find weekly note
|
||||
- extend markdown syntax highlights for [[links]]
|
||||
- get rid of `daily_finder.sh`
|
||||
- maybe choose template in create note
|
||||
|
||||
## Dones
|
||||
- [x] goto week
|
||||
- [x] create note, use default template
|
||||
- [x] follow links: create non-existing ones
|
||||
- [x] ,[ to insert link --> we can escape out and type double brackets
|
||||
- [x] shortcuts for todo and done in init.vim
|
||||
|
||||
54
README.md
54
README.md
@@ -32,6 +32,7 @@ lua << END
|
||||
require('telekasten').setup({
|
||||
home = vim.fn.expand("~/zettelkasten"),
|
||||
dailies = vim.fn.expand("~/zettelkasten/daily"),
|
||||
weeklies = vim.fn.expand("~/zettelkasten/weekly"),
|
||||
extension = ".md",
|
||||
daily_finder = "daily_finder.sh",
|
||||
|
||||
@@ -46,12 +47,15 @@ require('telekasten').setup({
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
weeklies_create_nonexisting = true,
|
||||
|
||||
-- templates for new notes
|
||||
-- template for new notes (new_note, follow_link)
|
||||
template_new_note = ZkCfg.home .. '/' .. 'templates/new_note.md',
|
||||
-- currently unused, hardcoded in daily_finder.sh:
|
||||
|
||||
-- template for newly created daily notes (goto_today)
|
||||
template_new_daily = ZkCfg.home .. '/' .. 'templates/daily.md',
|
||||
-- currently unused
|
||||
|
||||
-- template for newly created weekly notes (goto_thisweek)
|
||||
template_new_weekly= ZkCfg.home .. '/' .. 'templates/weekly.md',
|
||||
})
|
||||
END
|
||||
@@ -72,8 +76,10 @@ This will download the daily finder into the `bin/` folder of your home director
|
||||
|
||||
The plugin defines the following functions.
|
||||
|
||||
- `new_note` : prompts for title and creates new note by template, then shows it in Telescope
|
||||
- `find_notes()` : find notes by file name (title), via Telescope
|
||||
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope. If today's daily note is not present, it will be created, honoring the configured template
|
||||
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope. If today's daily note is not present, it can be created optionally, honoring the configured template
|
||||
- `find_weekly_notes()` : find weekly notes by week (file names, sorted, most recent first), via Telescope. If this week's weekly note is not present, it can be created optionally, honoring the configured template
|
||||
- `search_notes()`: live grep for word under cursor in all notes (search in notes), via Telescope
|
||||
- `insert_link()` : select a note by name, via Telescope, and place a `[[link]]` at the current cursor position
|
||||
- `follow_link()`: take text between brackets (linked note) and open a Telescope file finder with it: selects note to open (incl. preview) - optional note creation for non-existing notes
|
||||
@@ -89,15 +95,18 @@ To use one of the functions above, just run them with the `:lua ...` command.
|
||||
|
||||
### Note templates
|
||||
|
||||
The functions `find_daily_notes`, `goto_today`, and `follow_link` can create non-existing notes. This allows you to 'go to today' without having to create today's note beforehand. When you just type `[[some link]]` and then call `follow_link`, the 'some link' note can be generated.
|
||||
The functions `goto_today`, `goto_thisweek`, `find_daily_notes`, `find_weekly_notes`, and `follow_link` can create non-existing notes. This allows you to 'go to today' without having to create today's note beforehand. When you just type `[[some link]]` and then call `follow_link`, the 'some link' note can be generated.
|
||||
|
||||
The following table shows which command relies on what config option:
|
||||
|
||||
| telekasten function | config option |
|
||||
| --- | --- |
|
||||
| `goto_today` | `dailies_create_nonexisting` |
|
||||
| `find_daily_notes` | `dailies_create_nonexisting` |
|
||||
| telekasten function | config option | creates what |
|
||||
| --- | --- | --- |
|
||||
| `goto_today` | `dailies_create_nonexisting` | today's daily note |
|
||||
| `find_daily_notes` | `dailies_create_nonexisting` | today's daily note |
|
||||
| `goto_thisweek` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `find_weekly_notes` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `follow_link` | `follow_creates_nonexisting` |
|
||||
| `new_note` | always true |
|
||||
|
||||
If the associated option is `true`, non-existing notes will be created.
|
||||
|
||||
@@ -112,6 +121,8 @@ Currently, the following substitutions will be made during new note creation:
|
||||
| `{{title}}` | the title of the note | My new note |
|
||||
| `{{date}}` | date in iso format | 2021-11-21 |
|
||||
| `{{hdate}}` | date in human-readable format | Sunday, November 21st, 2021 |
|
||||
| `{{week}}` | week of the year | 46 |
|
||||
| `{{year}}` | year | 2021 |
|
||||
|
||||
As an example, this is my template for new notes:
|
||||
|
||||
@@ -130,6 +141,31 @@ title: {{hdate}}
|
||||
---
|
||||
```
|
||||
|
||||
And finally, the weekly notes (that I don't use a lot):
|
||||
|
||||
```markdown
|
||||
---
|
||||
title: {{year}}-W{{week}}
|
||||
date: {{hdate}}
|
||||
---
|
||||
|
||||
# Review Week {{week}} / {{year}}
|
||||
|
||||
---
|
||||
|
||||
## Highlights
|
||||
- **this**!
|
||||
- that!
|
||||
|
||||
## Monday link
|
||||
## Tuesday link
|
||||
## Wednesday link
|
||||
## Thursday link
|
||||
## Friday link
|
||||
## Saturday link
|
||||
## Sunday link
|
||||
```
|
||||
|
||||
## Bind it
|
||||
Usually, you would set up some key bindings, though:
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ local vim = vim
|
||||
ZkCfg = {
|
||||
home = vim.fn.expand("~/zettelkasten"),
|
||||
dailies = vim.fn.expand("~/zettelkasten/daily"),
|
||||
weeklies = vim.fn.expand("~/zettelkasten/weekly"),
|
||||
extension = ".md",
|
||||
daily_finder = "daily_finder.sh",
|
||||
|
||||
@@ -27,13 +28,14 @@ ZkCfg = {
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
dailies_create_nonexisting = true,
|
||||
weeklies_create_nonexisting = true,
|
||||
|
||||
-- templates for new notes
|
||||
template_new_note = ZkCfg.home .. '/' .. 'templates/new_note.md',
|
||||
-- currently unused, hardcoded in daily_finder.sh:
|
||||
template_new_daily = ZkCfg.home .. '/' .. 'templates/daily_tk.md',
|
||||
-- currently unused
|
||||
template_new_weekly= ZkCfg.home .. '/' .. 'templates/weekly.md',
|
||||
template_new_weekly= ZkCfg.home .. '/' .. 'templates/weekly_tk.md',
|
||||
}
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
@@ -49,6 +51,50 @@ local note_type_templates = {
|
||||
}
|
||||
|
||||
|
||||
local function file_exists(fname)
|
||||
local f=io.open(fname,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
local function daysuffix(day)
|
||||
if((day == '1') or (day == '21') or (day == '31')) then return 'st' end
|
||||
if((day == '2') or (day == '22')) then return 'nd' end
|
||||
if((day == '3') or (day == '33')) then return 'rd' end
|
||||
return 'th'
|
||||
end
|
||||
|
||||
local function linesubst(line, title)
|
||||
local substs = {
|
||||
date = os.date('%Y-%m-%d'),
|
||||
hdate = os.date('%A, %B %dx, %Y'):gsub('x', daysuffix(os.date('%d'))),
|
||||
week = os.date('%V'),
|
||||
year = os.date('%Y'),
|
||||
title = title,
|
||||
}
|
||||
for k, v in pairs(substs) do
|
||||
line = line:gsub("{{"..k.."}}", v)
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
local create_note_from_template = function (title, filepath, templatefn)
|
||||
-- first, read the template file
|
||||
local lines = {}
|
||||
for line in io.lines(templatefn) do
|
||||
lines[#lines+1] = line
|
||||
end
|
||||
|
||||
-- now write the output file, substituting vars line by line
|
||||
local ofile = io.open(filepath, 'a')
|
||||
for _, line in pairs(lines) do
|
||||
ofile:write(linesubst(line, title) .. '\n')
|
||||
end
|
||||
|
||||
ofile:close()
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- InstallDailyFinder:
|
||||
@@ -97,6 +143,14 @@ end
|
||||
--
|
||||
FindDailyNotes = function(opts)
|
||||
opts = {} or opts
|
||||
|
||||
local today = os.date("%Y-%m-%d")
|
||||
local fname = ZkCfg.dailies .. '/' .. today .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if ((fexists ~= true) and ((opts.dailies_create_nonexisting == true) or ZkCfg.dailies_create_nonexisting == true)) then
|
||||
create_note_from_template(today, fname, note_type_templates.daily)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Find daily note",
|
||||
@@ -111,6 +165,36 @@ end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- FindWeeklyNotes:
|
||||
-- ---------------
|
||||
--
|
||||
-- Select from daily notes
|
||||
--
|
||||
FindWeeklyNotes = function(opts)
|
||||
opts = {} or opts
|
||||
|
||||
local title = os.date("%Y-W%V")
|
||||
local fname = ZkCfg.weeklies .. '/' .. title .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if ((fexists ~= true) and ((opts.weeklies_create_nonexisting == true) or ZkCfg.weeklies_create_nonexisting == true)) then
|
||||
create_note_from_template(title, fname, note_type_templates.weekly)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Find weekly note",
|
||||
cwd = ZkCfg.weeklies,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- InsertLink:
|
||||
-- -----------
|
||||
@@ -149,46 +233,12 @@ end
|
||||
--
|
||||
-- find the file linked to by the word under the cursor
|
||||
--
|
||||
local function file_exists(fname)
|
||||
local f=io.open(fname,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
local function linesubst(line, title)
|
||||
local substs = {
|
||||
date = os.date('%Y-%m-%d'),
|
||||
title = title,
|
||||
}
|
||||
for k, v in pairs(substs) do
|
||||
line = line:gsub("{{"..k.."}}", v)
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
local create_note_from_template = function (title, filepath, templatefn)
|
||||
-- first, read the template file
|
||||
local lines = {}
|
||||
for line in io.lines(templatefn) do
|
||||
lines[#lines+1] = line
|
||||
end
|
||||
|
||||
-- now write the output file, substituting vars line by line
|
||||
local ofile = io.open(filepath, 'a')
|
||||
for _, line in pairs(lines) do
|
||||
ofile:write(linesubst(line, title) .. '\n')
|
||||
end
|
||||
|
||||
ofile:close()
|
||||
end
|
||||
|
||||
|
||||
FollowLink = function(opts)
|
||||
opts = {} or opts
|
||||
vim.cmd('normal yi]')
|
||||
local title = vim.fn.getreg('"0')
|
||||
local fname = ZkCfg.home .. '/' .. title .. ZkCfg.extension
|
||||
|
||||
local fname = ZkCfg.home .. '/' .. title .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if ((fexists ~= true) and ((opts.follow_creates_nonexisting == true) or ZkCfg.follow_creates_nonexisting == true)) then
|
||||
create_note_from_template(title, fname, note_type_templates.normal)
|
||||
@@ -216,13 +266,18 @@ end
|
||||
-- find today's daily note and create it if necessary.
|
||||
--
|
||||
GotoToday = function(opts)
|
||||
print('local version')
|
||||
opts = {} or opts
|
||||
local word = os.date("%Y-%m-%d")
|
||||
|
||||
local fname = ZkCfg.dailies .. '/' .. word .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
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)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Follow link to note...",
|
||||
prompt_title = "Goto today",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = word,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
@@ -277,6 +332,74 @@ end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- CreateNote:
|
||||
-- ------------
|
||||
--
|
||||
-- find the file linked to by the word under the cursor
|
||||
--
|
||||
local function on_create(title)
|
||||
if (title == nil) then return end
|
||||
|
||||
local fname = ZkCfg.home .. '/' .. title .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if (fexists ~= true) then
|
||||
create_note_from_template(title, fname, note_type_templates.normal)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Created note...",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = title,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
CreateNote = function(opts)
|
||||
opts = {} or opts
|
||||
vim.ui.input({prompt = 'Title: '}, on_create)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- GotoThisWeek:
|
||||
-- ----------
|
||||
--
|
||||
-- find this week's weekly note and create it if necessary.
|
||||
--
|
||||
GotoThisWeek = function(opts)
|
||||
print('local version')
|
||||
opts = {} or opts
|
||||
|
||||
local title = os.date("%Y-W%V")
|
||||
local fname = ZkCfg.weeklies .. '/' .. title .. ZkCfg.extension
|
||||
local fexists = file_exists(fname)
|
||||
if ((fexists ~= true) and ((opts.weeklies_create_nonexisting == true) or ZkCfg.weeklies_create_nonexisting == true)) then
|
||||
create_note_from_template(title, fname, note_type_templates.weekly)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Goto this week:",
|
||||
cwd = ZkCfg.weeklies,
|
||||
default_text = title,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Setup(cfg)
|
||||
--
|
||||
-- Overrides config with elements from cfg
|
||||
@@ -304,6 +427,9 @@ local M = {
|
||||
setup = Setup,
|
||||
install_daily_finder = InstallDailyFinder,
|
||||
goto_today = GotoToday,
|
||||
new_note = CreateNote,
|
||||
goto_thisweek = GotoThisWeek,
|
||||
find_weekly_notes = FindWeeklyNotes,
|
||||
}
|
||||
print('local version')
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user