2020-10-26 14:55:40 +00:00
|
|
|
local ZK = {}
|
2020-10-26 18:32:27 +00:00
|
|
|
|
2021-05-04 07:46:18 +00:00
|
|
|
local f = require 'zettelkasten.files'
|
2020-11-04 21:27:30 +00:00
|
|
|
local anchor = require 'zettelkasten.anchor'
|
|
|
|
local action = require 'zettelkasten.action'
|
2020-10-26 14:55:40 +00:00
|
|
|
|
2020-10-29 11:18:19 +00:00
|
|
|
-- Returns all zettel in path as a
|
|
|
|
-- { "anchor" = "path/to/zettel/anchor filename.md" }
|
|
|
|
-- table.
|
|
|
|
-- Recurses into subdirectories if recursive argument is true.
|
|
|
|
function ZK.get_zettel_list(path, recursive)
|
2021-05-04 07:46:18 +00:00
|
|
|
return f.get_anchors_and_paths(f.get_all_files(path, recursive or false))
|
2020-10-29 11:18:19 +00:00
|
|
|
end
|
|
|
|
|
2020-10-31 10:01:53 +00:00
|
|
|
-- Return a valid zettelkasten anchor for the current time,
|
|
|
|
-- composed of yymmddHHMM.
|
2020-11-04 21:27:30 +00:00
|
|
|
function ZK.get_anchor() return anchor.create() end
|
2020-10-30 15:30:37 +00:00
|
|
|
|
2020-11-04 21:27:30 +00:00
|
|
|
-- Open link under cursor, or next on line
|
|
|
|
function ZK.open_link() return action.open_selected() end
|
|
|
|
|
2021-05-03 15:31:28 +00:00
|
|
|
-- Create a new link under cursor
|
2021-05-04 07:46:18 +00:00
|
|
|
function ZK.make_link(visual) return action.make_link(visual) end
|
2021-05-03 15:31:28 +00:00
|
|
|
|
2021-05-04 12:06:59 +00:00
|
|
|
-- If invoked in reach of a valid link will try to follow said link.
|
|
|
|
-- Otherwise will take the current context and make a link out of it.
|
|
|
|
function ZK.open_or_make_link(visual)
|
|
|
|
if not ZK.open_link() then ZK.make_link(visual) end
|
|
|
|
end
|
|
|
|
|
2020-11-04 21:27:30 +00:00
|
|
|
return {
|
|
|
|
get_zettel_list = ZK.get_zettel_list,
|
|
|
|
get_anchor = ZK.get_anchor,
|
2021-05-03 15:31:28 +00:00
|
|
|
open_link = ZK.open_link,
|
2021-05-04 12:06:59 +00:00
|
|
|
make_link = ZK.make_link,
|
|
|
|
open_or_make_link = ZK.open_or_make_link
|
2020-11-04 21:27:30 +00:00
|
|
|
}
|