about summary refs log tree commit diff
path: root/lua/sketchbook/update_index.lua
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-02 23:19:11 +0200
committeriurii plugatarov <[email protected]>2024-08-02 23:19:11 +0200
commitf24a3ab9744a3f50eb8cacc06d4ef4c5f96875db (patch)
treee53c36d600f9ded45036d3489411cb82f26cb192 /lua/sketchbook/update_index.lua
parentdfee9611c0134def92d3c254ca4b067338ae7720 (diff)
downloadsketchbook.nvim-f24a3ab9744a3f50eb8cacc06d4ef4c5f96875db.tar.gz
fix
Diffstat (limited to 'lua/sketchbook/update_index.lua')
-rw-r--r--lua/sketchbook/update_index.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/lua/sketchbook/update_index.lua b/lua/sketchbook/update_index.lua
new file mode 100644
index 0000000..1a6044e
--- /dev/null
+++ b/lua/sketchbook/update_index.lua
@@ -0,0 +1,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") .. "](" .. note .. ")")
+    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