From c8dc1635f8a921269f714117f414bbc7ba24f9fd Mon Sep 17 00:00:00 2001 From: moxie Date: Sat, 14 Mar 2026 10:28:08 +0200 Subject: refactor: consolidate modules and improve structure --- lua/muwiki/links/url_handlers.lua | 71 --------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 lua/muwiki/links/url_handlers.lua (limited to 'lua/muwiki/links/url_handlers.lua') 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 -- cgit v1.2.3