Add function to open root index file

Call up `require 'zettelkasten'.open_index()` to open the file.
Pass along a file name `require 'zettelkasten'.open_index('home')` to
open said file at the zettel root instead.
This commit is contained in:
Marty Oehme 2021-07-26 22:26:15 +02:00
parent 98eeaf6fc7
commit aad77cff07
Signed by: Marty
GPG key ID: B7538B8F50A1C800
3 changed files with 45 additions and 8 deletions

View file

@ -52,4 +52,19 @@ function A.make_link(visual)
start_col))
end
return {open = A.open, open_selected = A.open_selected, make_link = A.make_link}
-- Opens an index.md file at the zettelkasten root directory whether it
-- exists or not.
function A.open_index_file(name)
local link = {
ref = o.zettel().rootdir .. "/" .. (name or "index") ..
o.zettel().extension
}
A.open(link)
end
return {
open = A.open,
open_selected = A.open_selected,
open_index_file = A.open_index_file,
make_link = A.make_link
}

View file

@ -28,10 +28,15 @@ function ZK.open_or_make_link(visual)
if not ZK.open_link() then ZK.make_link(visual) end
end
-- Open index file at zettel root directory. If title is passed in opens
-- `title`.<extension> file, otherwise defaults to `index`.<extension>.
function ZK.open_index(title) return action.open_index_file(title) end
return {
get_zettel_list = ZK.get_zettel_list,
get_anchor = ZK.get_anchor,
open_link = ZK.open_link,
make_link = ZK.make_link,
open_or_make_link = ZK.open_or_make_link
open_or_make_link = ZK.open_or_make_link,
open_index = ZK.open_index
}