docs/fix-links: handle #anchor targets on the same page

This commit is contained in:
Matt Sturgeon 2025-02-14 10:10:37 +00:00
parent 7f29e4b2ae
commit a39e0a6516
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299

View file

@ -18,9 +18,13 @@ 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
while hasPrefix("./", target) do
-- strip leading ./
target = sub(target, 3)
end
if hasPrefix("#", target) then
-- No-op for anchor targets on the same page
return nil
end
if not hasPrefix("https://", target) then
link.target = githubUrl .. target