|
| 1 | +local Docs = require("lazy.docs") |
| 2 | + |
| 3 | +local M = {} |
| 4 | + |
| 5 | +function M.suggested() |
| 6 | + return { |
| 7 | + "Salanoid/gitlogdiff.nvim", |
| 8 | + main = "gitlogdiff", |
| 9 | + dependencies = { |
| 10 | + "sindrets/diffview.nvim", |
| 11 | + "folke/snacks.nvim", |
| 12 | + }, |
| 13 | + cmd = "GitLogDiff", |
| 14 | + opts = { max_count = 300 }, |
| 15 | + } |
| 16 | +end |
| 17 | + |
| 18 | +function M.update() |
| 19 | + local name = "gitlogdiff" |
| 20 | + |
| 21 | + -- Update README.md |
| 22 | + Docs.save({ |
| 23 | + suggested = { |
| 24 | + content = [[{ |
| 25 | + "Salanoid/gitlogdiff.nvim", |
| 26 | + main = "gitlogdiff", |
| 27 | + dependencies = { |
| 28 | + "sindrets/diffview.nvim", |
| 29 | + "folke/snacks.nvim", |
| 30 | + }, |
| 31 | + cmd = "GitLogDiff", |
| 32 | + opts = { max_count = 300 }, |
| 33 | +}]], |
| 34 | + lang = "lua", |
| 35 | + }, |
| 36 | + }) |
| 37 | + |
| 38 | + -- Generate Vimdocs |
| 39 | + local readme = vim.fn.readfile("README.md") |
| 40 | + local lines = {} |
| 41 | + |
| 42 | + table.insert(lines, "*" .. name .. ".txt* Recent Git commits and diffs") |
| 43 | + table.insert(lines, "") |
| 44 | + table.insert(lines, "==============================================================================") |
| 45 | + table.insert(lines, "INTRODUCTION *" .. name .. "-intro*") |
| 46 | + table.insert(lines, "") |
| 47 | + |
| 48 | + local in_code_block = false |
| 49 | + for _, line in ipairs(readme) do |
| 50 | + if line:find("^<!%-%-") then |
| 51 | + -- Skip HTML comments |
| 52 | + elseif line:find("^```") then |
| 53 | + in_code_block = not in_code_block |
| 54 | + table.insert(lines, in_code_block and ">" or "<") |
| 55 | + elseif line:find("^%s*# ") then |
| 56 | + -- Skip |
| 57 | + elseif line:find("^%s*%[!%[") then |
| 58 | + -- Skip badges |
| 59 | + elseif line:find("^## ") then |
| 60 | + local title = line:match("^## (.*)") |
| 61 | + local tag = "*" .. name .. "-" .. title:lower():gsub("[%s/]+", "-"):gsub("%-+$", "") .. "*" |
| 62 | + table.insert(lines, "") |
| 63 | + table.insert(lines, "==============================================================================") |
| 64 | + table.insert(lines, title:upper() .. string.rep(" ", 78 - #title - #tag) .. tag) |
| 65 | + table.insert(lines, "") |
| 66 | + elseif line:find("^### ") then |
| 67 | + local title = line:match("^### (.*)") |
| 68 | + local tag = "*" .. name .. "-" .. title:lower():gsub("[%s/]+", "-"):gsub("%-+$", "") .. "*" |
| 69 | + table.insert(lines, "") |
| 70 | + table.insert(lines, title .. string.rep(" ", 78 - #title - #tag) .. tag) |
| 71 | + table.insert(lines, "") |
| 72 | + else |
| 73 | + if not in_code_block then |
| 74 | + line = line:gsub("%%", "%%%%") |
| 75 | + line = line:gsub("%[(.-)%]%(.-%)", "%1") |
| 76 | + line = line:gsub("%[(.-)%]", "%1") |
| 77 | + line = line:gsub("`(.-)`", "%1") |
| 78 | + end |
| 79 | + table.insert(lines, line) |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + table.insert(lines, "") |
| 84 | + table.insert(lines, " vim:tw=78:ts=8:ft=help:norl:") |
| 85 | + |
| 86 | + vim.fn.mkdir("doc", "p") |
| 87 | + vim.fn.writefile(lines, "doc/" .. name .. ".txt") |
| 88 | +end |
| 89 | + |
| 90 | +M.update() |
| 91 | + |
| 92 | +return M |
0 commit comments