From 97cbb42f24ef8836c2d7738e60d67515384c3f7c Mon Sep 17 00:00:00 2001 From: moxie Date: Sun, 15 Mar 2026 13:21:28 +0200 Subject: fix(utils): resolve relative paths correctly --- lua/muwiki/links.lua | 21 +++------------------ lua/muwiki/utils.lua | 8 +++++--- 2 files changed, 8 insertions(+), 21 deletions(-) (limited to 'lua') diff --git a/lua/muwiki/links.lua b/lua/muwiki/links.lua index 599ddb8..3302f3b 100644 --- a/lua/muwiki/links.lua +++ b/lua/muwiki/links.lua @@ -78,28 +78,13 @@ function M.open_link() return end - local wiki_root = get_wiki_root() - if not wiki_root then - return - end - if link.type == 'file' then - if vim.startswith(link.target, 'file://') then - local file_path = utils.resolve(link.target, nil) - vim.system({ 'xdg-open', file_path }, { detach = true }) - else - local ok, file_path = pcall(utils.resolve, link.target, wiki_root) - if not ok then - vim.notify(string.format('Cannot resolve path: %s', link.target), vim.log.levels.ERROR) - return - end - - vim.system({ 'xdg-open', file_path }, { detach = true }) - end + local file_path = utils.resolve(link.target, nil) + vim.system({ 'xdg-open', file_path }, { detach = true }) return end - local file_path = utils.resolve(link.target, wiki_root) + local file_path = utils.resolve(link.target, nil) utils.open_in_buffer(file_path) end diff --git a/lua/muwiki/utils.lua b/lua/muwiki/utils.lua index bc6094e..273a466 100644 --- a/lua/muwiki/utils.lua +++ b/lua/muwiki/utils.lua @@ -60,9 +60,11 @@ end function M.resolve(filepath, wiki_root) local path = filepath:gsub('^file://', '') local path_type = path:sub(1, 1) - if path_type ~= '/' and path_type ~= '~' then - local base = wiki_root and vim.fs.dirname(wiki_root) - or vim.fs.dirname(vim.api.nvim_buf_get_name(0)) + if path_type == '.' then + local current_dir = vim.fs.dirname(vim.api.nvim_buf_get_name(0)) + path = vim.fs.joinpath(current_dir, path) + elseif path_type ~= '/' and path_type ~= '~' then + local base = wiki_root or vim.fs.dirname(vim.api.nvim_buf_get_name(0)) path = vim.fs.joinpath(base, path) end return vim.fs.normalize(path) -- cgit v1.2.3