diff options
Diffstat (limited to 'lua/inbox/config.lua')
-rw-r--r-- | lua/inbox/config.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lua/inbox/config.lua b/lua/inbox/config.lua index 4692f5c..634b35d 100644 --- a/lua/inbox/config.lua +++ b/lua/inbox/config.lua @@ -54,12 +54,39 @@ local default_config = { ---@class inbox.Config local M = {} +function M.try_resolve(value, module) + if type(value) == "string" then + local is_ok, result = pcall(require, ("inbox.%s.%s"):format(module, value)) + if is_ok then + value = result + end + end + return value +end + +function M.parse_filters(filter_config) + local filters = {} + for content_type, items in pairs(filter_config) do + filters[content_type] = {} + for _, value in pairs(items) do + table.insert(filters[content_type], M.try_resolve(value, "filters")) + end + end + return filters +end + ---@param opts inbox.Config function M.setup(opts) local config = vim.tbl_deep_extend("keep", opts or {}, default_config) for k, v in pairs(config) do - M[k] = v + if k == "filters" then + M[k] = M.parse_filters(v) + elseif k == "indexer" then + M[k] = M.try_resolve(v, k) + else + M[k] = v + end end end |