diff options
| author | moxie <moxie@3kgcat.fi> | 2026-03-14 10:28:08 +0200 |
|---|---|---|
| committer | moxie <moxie@3kgcat.fi> | 2026-03-14 10:29:54 +0200 |
| commit | c8dc1635f8a921269f714117f414bbc7ba24f9fd (patch) | |
| tree | 336a0bb466a5e023c0a0e6472c9876ff7458de68 /lua/muwiki/paths.lua | |
| parent | ffc0482ab89924cb35155fa82033e3d0ddc6c93d (diff) | |
refactor: consolidate modules and improve structure
Diffstat (limited to 'lua/muwiki/paths.lua')
| -rw-r--r-- | lua/muwiki/paths.lua | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/lua/muwiki/paths.lua b/lua/muwiki/paths.lua index aa07776..f679888 100644 --- a/lua/muwiki/paths.lua +++ b/lua/muwiki/paths.lua @@ -1,4 +1,3 @@ - local M = {} function M.get_path_type(path) @@ -11,40 +10,16 @@ function M.get_path_type(path) end end -function M.resolve_relative(path, base) - local result - - if vim.startswith(path, './') then - result = vim.fs.joinpath(base, path:sub(3)) - elseif vim.startswith(path, '../') then - local current_base = base - local remaining = path - - while vim.startswith(remaining, '../') do - current_base = vim.fs.dirname(current_base) - remaining = remaining:sub(4) - end - - result = vim.fs.joinpath(current_base, remaining) - else - result = vim.fs.joinpath(base, path) - end - - return vim.fs.normalize(result) -end - function M.resolve(filepath, current_file) local path_type = M.get_path_type(filepath) - if path_type == 'absolute' then - return vim.fs.normalize(filepath) - elseif path_type == 'home' then - return vim.fs.normalize(filepath) - else + if path_type == 'relative' then local base = current_file and vim.fs.dirname(current_file) - or vim.fs.dirname(vim.api.nvim_buf_get_name(0)) - return M.resolve_relative(filepath, base) + or vim.fs.dirname(vim.api.nvim_buf_get_name(0)) + filepath = vim.fs.joinpath(base, filepath) end + + return vim.fs.normalize(filepath) end function M.strip_file_protocol(url) |
