Skip to content

Commit 62acc76

Browse files
committed
Improve documentation generation.
Details: - Don't enclose tag link as inline code, as it stands out a bit too much (because there are *a lot* of links in help pages). Instead improve `<xxx>` escape code to ignore only actual part of markdown link. Affecting links (https://neovim.io/doc/user/helptag.html?tag=<Leader>) was the initial problem of why inline code "escape" was added in the first place. - Make "Generated ..." note centered and below centered images in the READMEs. - Make first section in documentation pages have "module" anchor. Otherwise it was `minixxx` which is redundant as there is already `mini.xxx` anchor earlier. - Create a single 'mini.nvim/_metadata.yml' to populate common metadata for all pages (instead of adding to every page via script). This also contains a dedicated CSS that hides Quarto titles (which are often redundant). NOTE: do so only in 'mini.nvim' pages and not ont he whole site because showing titles of blog posts is useful.
1 parent 6b0c75b commit 62acc76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2531
-2588
lines changed

_scripts/mini_nvim.lua

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ local make_anchor = function(x)
1919
return (x:lower():gsub('[^%w%.%-_]', ''):gsub('%s', '-'):gsub('<(.-)>', '\\<%1\\>'))
2020
end
2121

22+
-- Metadata ===================================================================
23+
local metadata_lines = {
24+
-- Hide displaying the title as it is redundant and out of place
25+
'format:',
26+
' html:',
27+
' include-in-header:',
28+
' - text: "<style> .quarto-title > h1.title { display: none } </style>"',
29+
-- Show more nested headers (useful for documentation pages)
30+
'toc-depth: 5',
31+
}
32+
vim.fn.writefile(metadata_lines, 'mini.nvim/_metadata.yml')
33+
2234
-- Help files =================================================================
2335
local get_help_tags = function()
2436
local tags_path = '_deps/mini.nvim/doc/tags'
@@ -115,36 +127,39 @@ local add_help_syntax = function(lines, tags)
115127

116128
local populate_bad_ranges = function(s)
117129
bad_ranges = {}
130+
-- Inline code
118131
s:gsub('`().-()`', function(from, to) table.insert(bad_ranges, { from, to }) end)
119-
s:gsub('()%b[]%b()()', function(from, to) table.insert(bad_ranges, { from, to }) end)
132+
-- Actual link (but not visible part!) of markdown link
133+
s:gsub('%b[]()%b()()', function(from, to) table.insert(bad_ranges, { from, to }) end)
120134
end
121135

122136
local repl_link = function(m)
123137
-- Escpe special characters to be usable inside markdown link
124138
if tags[m] == nil then
125139
local text_escaped = m:gsub('[)(]', '\\%1')
126-
return string.format('[`%s`](https://neovim.io/doc/user/helptag.html?tag=%s)', m, text_escaped)
140+
return string.format('[%s](https://neovim.io/doc/user/helptag.html?tag=%s)', m, text_escaped)
127141
end
128142

129-
return string.format('[`%s`](%s.qmd#%s)', m, tags[m], make_anchor(m))
143+
return string.format('[%s](%s.qmd#%s)', m, tags[m], make_anchor(m))
130144
end
131145

132146
local repl_right_anchor = function(m)
133147
-- Transform right anchor into a heading (for table of contents entry).
134148
-- Compute more natural title. Common tag->title transformations:
135149
-- - `*MiniAi*` -> "Module" ("Overview" is commonly used later as
136-
-- a 'MiniXxx-overview' tag).
150+
-- a 'MiniXxx-overview' tag). Both as title and anchor.
137151
-- - `*MiniAi.find_textobject()*` -> "find_textobject()"
138152
-- - `*MiniAi-builtin-textobjects*` -> "Builtin textobjects"
139153
-- - `*mini.nvim-disabling-recipes*` -> "Disabling recipes"
140154
-- - `:DepsAdd` -> ":DepsAdd"
141-
local text = m:find('^Mini%w+$') ~= nil and 'Module'
142-
or (m:match('^Mini%w+(%W.+)$') or m:match('^mini%.%w+(%W.+)$') or m)
155+
m = m:find('^Mini%w+$') ~= nil and 'Module' or m
156+
local text = m:match('^Mini%w+(%W.+)$') or m:match('^mini%.%w+(%W.+)$') or m
143157
local char_one, char_two = text:sub(1, 1), text:sub(2, 2)
144158
local title = char_one == '.' and text:sub(2)
145159
or (char_one == '-' and (char_two:upper() .. text:sub(3):gsub('%-', ' ')) or text)
146160

147-
-- Preserve original tag as anchor for other links to work more naturally
161+
-- Preserve original tag as anchor for other converted links (coming from
162+
-- the help files) to work more naturally
148163
return string.format('### %s {#%s}\n', title, make_anchor(m))
149164
end
150165

@@ -257,17 +272,23 @@ local add_hierarchical_heading_anchors = function(lines)
257272
end
258273

259274
local add_source_note = function(lines)
260-
table.insert(lines, 1, "_Generated from the `main` branch of 'mini.nvim'_")
261-
table.insert(lines, 2, '')
275+
local msg = "_Generated from the `main` branch of 'mini.nvim'_"
276+
if lines[1]:find('align="center"') ~= nil then
277+
-- Center align if after center aligned element (i.e. top README image)
278+
table.insert(lines, 2, '<p align="center">' .. msg .. '</p>')
279+
table.insert(lines, 3, '')
280+
else
281+
table.insert(lines, 1, msg)
282+
table.insert(lines, 2, '')
283+
end
262284
end
263285

264286
local adjust_header_footer = function(lines, title)
265287
-- Add informative header for better search
266288
table.insert(lines, 1, '---')
267289
table.insert(lines, 2, string.format('title: "%s"', title))
268-
table.insert(lines, 3, 'toc-depth: 5')
269-
table.insert(lines, 4, '---')
270-
table.insert(lines, 5, '')
290+
table.insert(lines, 3, '---')
291+
table.insert(lines, 4, '')
271292

272293
-- Remove modeline
273294
if lines[#lines]:find('^ vim:') then
@@ -360,8 +381,9 @@ local adjust_readmes = function()
360381
-- Main README
361382
local path = vim.fs.joinpath('mini.nvim/index.md')
362383
local lines = vim.fn.readfile(path)
363-
adjust_header_footer(lines, 'mini.nvim')
364384
replace_help_links(lines)
385+
add_source_note(lines)
386+
adjust_header_footer(lines, 'mini.nvim')
365387
vim.fn.writefile(lines, path)
366388
end
367389

mini.nvim/_metadata.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
format:
2+
html:
3+
include-in-header:
4+
- text: "<style> .quarto-title > h1.title { display: none } </style>"
5+
toc-depth: 5

0 commit comments

Comments
 (0)