blob: 22fa47ffd07f48c78caa70b2872dc602a1689332 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
local M = {}
function M.update_index()
local notes_dir = vim.g.notes_directory or "~/notes/"
notes_dir = vim.fn.expand(notes_dir)
local index_file = notes_dir .. "index.md"
local notes = vim.fn.globpath(notes_dir, "*.md", false, true)
local content = { "# Index", "" }
for _, note in ipairs(notes) do
if vim.fn.fnamemodify(note, ":t") ~= "index.md" then
table.insert(content, "- [[" .. vim.fn.fnamemodify(note, ":t:r") .. "]]")
end
end
local file = io.open(index_file, "w")
for _, line in ipairs(content) do
file:write(line .. "\n")
end
file:close()
print("Index updated")
end
return M
|