mirror of
https://github.com/nix-community/nixvim.git
synced 2025-12-01 14:41:05 +01:00
docs/fix-links: init
The README/CONTRIBUTING files are authored with GitHub in mind, but we want to re-use them for the docs website. Replace the existing simple substitution with a pandoc AST-based filter.
This commit is contained in:
parent
ff63fc92ed
commit
7f29e4b2ae
3 changed files with 84 additions and 6 deletions
40
docs/fix-links/filter.lua
Normal file
40
docs/fix-links/filter.lua
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
local len = pandoc.text.len
|
||||
local sub = pandoc.text.sub
|
||||
|
||||
-- True if str starts with prefix
|
||||
local function hasPrefix(prefix, str)
|
||||
local pfxLen = len(prefix)
|
||||
local strLen = len(str)
|
||||
if pfxLen == strLen then
|
||||
return prefix == str
|
||||
end
|
||||
if pfxLen < strLen then
|
||||
return prefix == sub(str, 1, pfxLen)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Link(link)
|
||||
local target = link.target
|
||||
-- Check for relative links
|
||||
-- TODO: handle ../
|
||||
if hasPrefix("./", target) then
|
||||
link.target = githubUrl .. sub(target, 3)
|
||||
return link
|
||||
end
|
||||
if not hasPrefix("https://", target) then
|
||||
link.target = githubUrl .. target
|
||||
return link
|
||||
end
|
||||
|
||||
-- Check for absolute links, pointing to the docs website
|
||||
if docsUrl == target then
|
||||
link.target = "."
|
||||
return link
|
||||
end
|
||||
if hasPrefix(docsUrl, target) then
|
||||
local i = len(docsUrl) + 1
|
||||
link.target = sub(target, i)
|
||||
return link
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue