build: utility method to create plugin list in markdown

This commit is contained in:
Folke Lemaitre 2022-12-30 23:58:01 +01:00
parent 45d669f61c
commit fb46cb5862
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 14 additions and 3 deletions

View File

@ -36,7 +36,7 @@ function M.save(contents)
if not readme:find(pattern) then if not readme:find(pattern) then
error("tag " .. tag .. " not found") error("tag " .. tag .. " not found")
end end
if tag == "commands" or tag == "colors" then if tag == "commands" or tag == "colors" or tag == "plugins" then
readme = readme:gsub(pattern, "%1\n\n" .. content .. "\n\n%2") readme = readme:gsub(pattern, "%1\n\n" .. content .. "\n\n%2")
else else
readme = readme:gsub(pattern, "%1\n\n```lua\n" .. content .. "\n```\n\n%2") readme = readme:gsub(pattern, "%1\n\n```lua\n" .. content .. "\n```\n\n%2")
@ -135,6 +135,15 @@ function M.update()
vim.cmd.checktime() vim.cmd.checktime()
end end
M.update() function M.plugins()
local Config = require("lazy.core.config")
local lines = { "## Plugins", "" }
Util.foreach(Config.plugins, function(name, plugin)
if plugin.url then
lines[#lines + 1] = "- [" .. name .. "](" .. plugin.url:gsub("%.git$", "") .. ")"
end
end)
M.save({ plugins = table.concat(lines, "\n") })
end
return M return M

View File

@ -209,7 +209,9 @@ end
function M.foreach(t, fn) function M.foreach(t, fn)
---@type string[] ---@type string[]
local keys = vim.tbl_keys(t) local keys = vim.tbl_keys(t)
pcall(table.sort, keys) pcall(table.sort, keys, function(a, b)
return a:lower() < b:lower()
end)
for _, key in ipairs(keys) do for _, key in ipairs(keys) do
fn(key, t[key]) fn(key, t[key])
end end