aboutsummaryrefslogtreecommitdiff
path: root/lua/muwiki/utils.lua
diff options
context:
space:
mode:
authormoxie <moxie@3kgcat.fi>2026-03-15 06:41:37 +0200
committermoxie <moxie@3kgcat.fi>2026-03-15 10:05:06 +0200
commit49c1e9d1fc3d6bf8748756a8543d8c1b7287940f (patch)
tree8e03c663f10c2a0a17b44bef6a3dbf575582fb2c /lua/muwiki/utils.lua
parentc8dc1635f8a921269f714117f414bbc7ba24f9fd (diff)
refactor: move template/mkdir features to user-configured autocmds
- Remove auto-mkdir autocmd from init.lua (now user-configured) - Remove template system entirely (now user-configured) - Rename io.lua -> utils.lua - Inline single-use functions (handle_web_link, handle_file_link, etc.) - Remove security warnings for external files - Remove unused config options: use_template, template, date_fmt - Simplify utils.resolve() without wiki root validation - Update all documentation examples BREAKING CHANGE: Users must now add their own autocmds for: - Auto-creating directories on save (BufWritePre) - Applying templates to new files (BufNewFile) See README.md for updated configuration examples.
Diffstat (limited to 'lua/muwiki/utils.lua')
-rw-r--r--lua/muwiki/utils.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/lua/muwiki/utils.lua b/lua/muwiki/utils.lua
new file mode 100644
index 0000000..af22c8e
--- /dev/null
+++ b/lua/muwiki/utils.lua
@@ -0,0 +1,57 @@
+local config = require('muwiki.config')
+local paths = require('muwiki.paths')
+
+local M = {}
+
+function M.file_exists(path)
+ local stat = vim.uv.fs_stat(path)
+ return stat and stat.type == 'file'
+end
+
+function M.dir_exists(path)
+ local stat = vim.uv.fs_stat(path)
+ return stat and stat.type == 'directory'
+end
+
+function M.open_in_buffer(filepath)
+ local bufnr = vim.fn.bufnr(filepath, true)
+ vim.api.nvim_win_set_buf(0, bufnr)
+end
+
+function M.open_index(name)
+ local wiki_path = config.wiki_path(name)
+ if not wiki_path then
+ return
+ end
+
+ local index_path = vim.fs.joinpath(wiki_path, config.options.index_file)
+ M.open_in_buffer(index_path)
+end
+
+function M.resolve(filepath, wiki_root)
+ local path = paths.strip_file_protocol(filepath)
+ return paths.resolve(path, wiki_root)
+end
+
+function M.is_text_file(ext)
+ local ext_lower = ext:lower()
+ for _, text_ext in ipairs(config.options.text_extensions) do
+ if ext_lower == text_ext then
+ return true
+ end
+ end
+ return false
+end
+
+function M.normalize_filename(text)
+ local normalized = text:lower()
+ normalized = normalized:gsub('%s+', '_')
+ normalized = normalized:gsub('[^%w_%-%.]', '')
+ return normalized
+end
+
+function M.open_wiki_file(filepath)
+ M.open_in_buffer(filepath)
+end
+
+return M