mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
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).
This commit is contained in:
parent
53f9d242ff
commit
6f8d8f7aee
1 changed files with 10 additions and 6 deletions
|
@ -16,16 +16,20 @@ end
|
||||||
|
|
||||||
function Link(link)
|
function Link(link)
|
||||||
local target = link.target
|
local target = link.target
|
||||||
-- Check for relative links
|
|
||||||
|
-- Check for targets on the same page
|
||||||
-- TODO: handle ../
|
-- TODO: handle ../
|
||||||
while hasPrefix("./", target) do
|
local bareTarget, _ = target:gsub("[#?].*$", "")
|
||||||
-- strip leading ./
|
-- strip leading ./
|
||||||
target = sub(target, 3)
|
while hasPrefix("./", bareTarget) do
|
||||||
|
bareTarget = sub(bareTarget, 3)
|
||||||
end
|
end
|
||||||
if hasPrefix("#", target) then
|
-- No-op for targets on the same page
|
||||||
-- No-op for anchor targets on the same page
|
if bareTarget == "" or bareTarget == "." then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Relative links should target the github repo
|
||||||
if not hasPrefix("https://", target) then
|
if not hasPrefix("https://", target) then
|
||||||
link.target = githubUrl .. target
|
link.target = githubUrl .. target
|
||||||
return link
|
return link
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue