fix(help): sort tags files for readmes so tags work properly. Fixes #67

This commit is contained in:
Folke Lemaitre 2022-12-21 18:23:27 +01:00
parent eab449b9e5
commit 2fd78fbed8
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 7 additions and 5 deletions

View File

@ -7,7 +7,7 @@ function M.index(plugin)
if Config.options.readme.skip_if_doc_exists and vim.loop.fs_stat(plugin.dir .. "/doc") then if Config.options.readme.skip_if_doc_exists and vim.loop.fs_stat(plugin.dir .. "/doc") then
return {} return {}
end end
---@type {file:string, tag:string, line:string}[] ---@type table<string,{file:string, tag:string, line:string}>
local tags = {} local tags = {}
for _, file in ipairs(Config.options.readme.files) do for _, file in ipairs(Config.options.readme.files) do
file = plugin.dir .. "/" .. file file = plugin.dir .. "/" .. file
@ -18,7 +18,7 @@ function M.index(plugin)
if title then if title then
local tag = plugin.name .. "-" .. title:lower():gsub("%W+", "-") local tag = plugin.name .. "-" .. title:lower():gsub("%W+", "-")
tag = tag:gsub("%-+", "-"):gsub("%-$", "") tag = tag:gsub("%-+", "-"):gsub("%-$", "")
table.insert(tags, { tag = tag, line = line, file = plugin.name .. ".md" }) tags[tag] = { tag = tag, line = line, file = plugin.name .. ".md" }
end end
end end
table.insert(lines, [[<!-- vim: set ft=markdown: -->]]) table.insert(lines, [[<!-- vim: set ft=markdown: -->]])
@ -40,12 +40,14 @@ function M.update()
---@type {file:string, tag:string, line:string}[] ---@type {file:string, tag:string, line:string}[]
local tags = {} local tags = {}
for _, plugin in pairs(Config.plugins) do for _, plugin in pairs(Config.plugins) do
vim.list_extend(tags, M.index(plugin)) for key, tag in pairs(M.index(plugin)) do
tags[key] = tag
end
end end
local lines = { [[!_TAG_FILE_ENCODING utf-8 //]] } local lines = { [[!_TAG_FILE_ENCODING utf-8 //]] }
for _, tag in ipairs(tags) do Util.foreach(tags, function(_, tag)
table.insert(lines, ("%s\t%s\t/%s"):format(tag.tag, tag.file, tag.line)) table.insert(lines, ("%s\t%s\t/%s"):format(tag.tag, tag.file, tag.line))
end end)
Util.write_file(docs .. "/tags", table.concat(lines, "\n")) Util.write_file(docs .. "/tags", table.concat(lines, "\n"))
end end