aboutsummaryrefslogtreecommitdiff
path: root/lua/muwiki/config.lua
blob: 362cc26023a52b1e8552cc0e89330e71321e4929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local M = {}

M.options = {
  dirs = nil,
  index_file = 'index.md',
  text_extensions = {},
}

function M.setup(opts)
  opts = opts or {}

  if opts.dirs then
    M.options.dirs = {}
    for _, dir in ipairs(opts.dirs) do
      local path = vim.fs.normalize(dir.path)
      if not vim.endswith(path, '/') then
        path = path .. '/'
      end
      table.insert(M.options.dirs, { name = dir.name, path = path })
    end
  end

  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
  end

  for _, dir in ipairs(M.options.dirs or {}) do
    local stat = vim.uv.fs_stat(dir.path)
    if not (stat and stat.type == 'directory') then
      vim.notify('Wiki directory not found: ' .. dir.path, vim.log.levels.WARN)
    end
  end
end

return M