-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocs.lua
More file actions
90 lines (79 loc) · 2.52 KB
/
docs.lua
File metadata and controls
90 lines (79 loc) · 2.52 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
local Docs = require("lazy.docs")
local M = {}
function M.suggested()
return {
"Salanoid/gitlogdiff.nvim",
main = "gitlogdiff",
dependencies = {
"sindrets/diffview.nvim",
},
cmd = "GitLogDiff",
opts = { max_count = 300 },
}
end
function M.update()
local name = "gitlogdiff"
-- Update README.md
Docs.save({
suggested = {
content = [[{
"Salanoid/gitlogdiff.nvim",
main = "gitlogdiff",
dependencies = {
"sindrets/diffview.nvim",
},
cmd = "GitLogDiff",
opts = { max_count = 300 },
}]],
lang = "lua",
},
})
-- Generate Vimdocs
local readme = vim.fn.readfile("README.md")
local lines = {}
table.insert(lines, "*" .. name .. ".txt* Recent Git commits and diffs")
table.insert(lines, "")
table.insert(lines, "==============================================================================")
table.insert(lines, "INTRODUCTION *" .. name .. "-intro*")
table.insert(lines, "")
local in_code_block = false
for _, line in ipairs(readme) do
if line:find("^<!%-%-") then
-- Skip HTML comments
elseif line:find("^```") then
in_code_block = not in_code_block
table.insert(lines, in_code_block and ">" or "<")
elseif line:find("^%s*# ") then
-- Skip
elseif line:find("^%s*%[!%[") then
-- Skip badges
elseif line:find("^## ") then
local title = line:match("^## (.*)")
local tag = "*" .. name .. "-" .. title:lower():gsub("[%s/]+", "-"):gsub("%-+$", "") .. "*"
table.insert(lines, "")
table.insert(lines, "==============================================================================")
table.insert(lines, title:upper() .. string.rep(" ", 78 - #title - #tag) .. tag)
table.insert(lines, "")
elseif line:find("^### ") then
local title = line:match("^### (.*)")
local tag = "*" .. name .. "-" .. title:lower():gsub("[%s/]+", "-"):gsub("%-+$", "") .. "*"
table.insert(lines, "")
table.insert(lines, title .. string.rep(" ", 78 - #title - #tag) .. tag)
table.insert(lines, "")
else
if not in_code_block then
line = line:gsub("%%", "%%%%")
line = line:gsub("%[(.-)%]%(.-%)", "%1")
line = line:gsub("%[(.-)%]", "%1")
line = line:gsub("`(.-)`", "%1")
end
table.insert(lines, line)
end
end
table.insert(lines, "")
table.insert(lines, " vim:tw=78:ts=8:ft=help:norl:")
vim.fn.mkdir("doc", "p")
vim.fn.writefile(lines, "doc/" .. name .. ".txt")
end
M.update()
return M