aboutsummaryrefslogtreecommitdiff
path: root/lua/muwiki/links/url_handlers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/muwiki/links/url_handlers.lua')
-rw-r--r--lua/muwiki/links/url_handlers.lua71
1 files changed, 0 insertions, 71 deletions
diff --git a/lua/muwiki/links/url_handlers.lua b/lua/muwiki/links/url_handlers.lua
deleted file mode 100644
index f84715a..0000000
--- a/lua/muwiki/links/url_handlers.lua
+++ /dev/null
@@ -1,71 +0,0 @@
-local config = require('muwiki.config')
-local paths = require('muwiki.paths')
-local files = require('muwiki.files')
-local fs = require('muwiki.fs')
-
-local M = {}
-
-function M.handle_web_link(url)
- if not config.options.use_external_handlers then
- return
- end
- files.open_external(url)
-end
-
-local function resolve_file_url(url)
- local path = paths.strip_file_protocol(url)
- local resolved_path
-
- local path_type = paths.get_path_type(path)
-
- if path_type == 'absolute' then
- resolved_path = path
- elseif path_type == 'home' then
- resolved_path = vim.fs.normalize(path)
- else
- local current_dir = vim.fs.dirname(vim.api.nvim_buf_get_name(0))
- resolved_path = paths.resolve_relative(path, current_dir)
- end
-
- return 'file://' .. vim.fs.normalize(resolved_path)
-end
-
-function M.handle_file_url(url)
- if not config.options.use_external_handlers then
- return
- end
-
- local absolute_url = resolve_file_url(url)
- files.open_external(absolute_url)
-end
-
-function M.handle_file_link(target, wiki_root)
- local ok, file_path = pcall(files.resolve, target, wiki_root)
- if not ok then
- vim.notify(string.format('Cannot resolve path: %s', target), vim.log.levels.ERROR)
- return
- end
-
- if not fs.file_exists(file_path) then
- vim.notify(string.format('File not found: %s', file_path), vim.log.levels.ERROR)
- return
- end
-
- local ext = file_path:match('%.([^%.]+)$') or ''
- if not files.is_text_file(ext) then
- if not config.options.use_external_handlers then
- return
- end
- files.open_external(file_path)
- return
- end
-
- files.open_in_buffer(file_path)
-end
-
-function M.handle_wiki_link(target, wiki_root)
- local file_path = files.resolve(target, wiki_root)
- files.open_wiki_file(file_path)
-end
-
-return M