Skip to content

Commit 6f8d8f7

Browse files
committed
docs/fix-links: generalise checks for links targeting .
- Strip trailing `?query` and/or `#anchor` - Strip leading `./` recursively - Check if what's left is `""` or `"."` Any link that targets the current page should be left as-is (no-op).
1 parent 53f9d24 commit 6f8d8f7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/fix-links/filter.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ end
1616

1717
function Link(link)
1818
local target = link.target
19-
-- Check for relative links
19+
20+
-- Check for targets on the same page
2021
-- TODO: handle ../
21-
while hasPrefix("./", target) do
22-
-- strip leading ./
23-
target = sub(target, 3)
22+
local bareTarget, _ = target:gsub("[#?].*$", "")
23+
-- strip leading ./
24+
while hasPrefix("./", bareTarget) do
25+
bareTarget = sub(bareTarget, 3)
2426
end
25-
if hasPrefix("#", target) then
26-
-- No-op for anchor targets on the same page
27+
-- No-op for targets on the same page
28+
if bareTarget == "" or bareTarget == "." then
2729
return nil
2830
end
31+
32+
-- Relative links should target the github repo
2933
if not hasPrefix("https://", target) then
3034
link.target = githubUrl .. target
3135
return link

0 commit comments

Comments
 (0)