diff options
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) |
