diff options
| author | moxie <moxie@3kgcat.fi> | 2026-03-16 02:21:16 +0200 |
|---|---|---|
| committer | moxie <moxie@3kgcat.fi> | 2026-03-16 02:30:19 +0200 |
| commit | c566653a645c8317f336043117766745304b7887 (patch) | |
| tree | 2014fc5f94dd7b0c7f820f0ba92cc064abf2988e | |
| parent | 379e5af690c8ab298ef5d32fcaddae070c4ff8a5 (diff) | |
refactor: normalize text_extensions at config time
| -rw-r--r-- | lua/muwiki/config.lua | 7 | ||||
| -rw-r--r-- | lua/muwiki/links.lua | 9 |
2 files changed, 11 insertions, 5 deletions
diff --git a/lua/muwiki/config.lua b/lua/muwiki/config.lua index 831e406..362cc26 100644 --- a/lua/muwiki/config.lua +++ b/lua/muwiki/config.lua @@ -23,6 +23,13 @@ function M.setup(opts) for key, value in pairs(opts) do if key == 'dirs' then -- handled above + elseif key == 'text_extensions' then + -- Normalize extensions by stripping leading dots + M.options.text_extensions = {} + for _, ext in ipairs(value) do + local normalized = ext:gsub("^%.", "") + table.insert(M.options.text_extensions, normalized) + end elseif M.options[key] ~= nil then M.options[key] = value end diff --git a/lua/muwiki/links.lua b/lua/muwiki/links.lua index 2972973..2213dae 100644 --- a/lua/muwiki/links.lua +++ b/lua/muwiki/links.lua @@ -13,12 +13,11 @@ local M = {} ---@field cmd string|function Command or function to handle the URL ---@field exts string[]? Optional list of file extensions this handler supports +-- TODO: Support compound extensions like "tar.gz" or "min.js" local function is_text_extension(ext) - local text_exts = config.options.text_extensions or {} - ext = ext:gsub("^%.", "") - for _, text_ext in ipairs(text_exts) do - local normalized = text_ext:gsub("^%.", "") - if normalized == ext then + local target = ext:gsub("^%.", "") + for _, cfg_ext in ipairs(config.options.text_extensions or {}) do + if cfg_ext == target then return true end end |
