Skip to content

Commit

Permalink
Fix Windows separators in URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
goerz committed Jan 5, 2024
1 parent c37ef77 commit 1bd05b0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
30 changes: 22 additions & 8 deletions src/write_inventory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function write_inventory(doc::Documenter.Document)
priority = -1
for navnode in doc.internal.navlist
name = replace(splitext(navnode.page)[1], "\\" => "/")
uri = pretty_url(ctx, get_url(ctx, navnode.page))
dispname = get_navnode_dispname(navnode, ctx)
uri = _get_inventory_uri(doc, ctx, navnode)
dispname = _get_inventory_dispname(doc, ctx, navnode)
line = "$name $domain:$role $priority $uri $dispname\n"
write(io_inv, line)
write(io_toml, "[[$domain.$role]]\n")
Expand All @@ -92,8 +92,8 @@ function write_inventory(doc::Documenter.Document)
# anchor not unique -> exclude from inventory
continue
end
uri = get_inventory_uri(doc, ctx, name, anchor)
dispname = get_inventory_dispname(name, anchor)
uri = _get_inventory_uri(doc, ctx, name, anchor)
dispname = _get_inventory_dispname(doc, ctx, name, anchor)
line = "$name $domain:$role $priority $uri $dispname\n"
write(io_inv, line)
write(io_toml, "[[$domain.$role]]\n")
Expand All @@ -111,7 +111,7 @@ function write_inventory(doc::Documenter.Document)
# anchor not unique -> exclude from inventory
continue
end
uri = get_inventory_uri(doc, ctx, name, anchor)
uri = _get_inventory_uri(doc, ctx, name, anchor)
role = lowercase(doccat(anchor.object))
dispname = "-"
line = "$name $domain:$role $priority $uri $dispname\n"
Expand All @@ -129,9 +129,13 @@ function write_inventory(doc::Documenter.Document)
end


function get_inventory_uri(doc, ctx, name, anchor)
function _get_inventory_uri(doc, ctx, name::AbstractString, anchor::Documenter.Anchor)
filename = relpath(anchor.file, doc.user.build)
page_url = pretty_url(ctx, get_url(ctx, filename))
if Sys.iswindows()
# https://github.com/JuliaDocs/Documenter.jl/issues/2387
page_url = replace(page_url, "\\" => "/")
end
label = escapeuri(Documenter.anchor_label(anchor))
if label == name
uri = page_url * raw"#$"
Expand All @@ -142,7 +146,17 @@ function get_inventory_uri(doc, ctx, name, anchor)
end


function get_inventory_dispname(name, anchor)
function _get_inventory_uri(doc, ctx, navnode::Documenter.NavNode)
uri = pretty_url(ctx, get_url(ctx, navnode.page))
if Sys.iswindows()
# https://github.com/JuliaDocs/Documenter.jl/issues/2387
uri = replace(uri, "\\" => "/")
end
return uri
end


function _get_inventory_dispname(doc, ctx, name::AbstractString, anchor::Documenter.Anchor)
dispname = mdflatten(anchor.node)
if dispname == name
dispname = "-"
Expand All @@ -151,7 +165,7 @@ function get_inventory_dispname(name, anchor)
end


function get_navnode_dispname(navnode, ctx)
function _get_inventory_dispname(doc, ctx, navnode::Documenter.NavNode)
dispname = navnode.title_override
if isnothing(dispname)
page = getpage(ctx, navnode)
Expand Down
12 changes: 9 additions & 3 deletions test/test_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include("run_makedocs.jl")

Base.eval(Main, quote
using DocumenterInterLinks
PAGES = []
PAGES = [] # We don't care about the order of pages for the test
end)

run_makedocs(
Expand Down Expand Up @@ -60,23 +60,29 @@ include("run_makedocs.jl")
for spec in specs
@test !isnothing(inventory[spec])
end
for item in inventory
# URIs should never use Windows path separators
@test !contains(item.uri, "\\")
end
end

inventory_file = joinpath(dir, "build", "inventory.toml.gz")
@test isfile(inventory_file)
if isfile(inventory_file)
inventory = Inventory(inventory_file; root_url="")
inventory_toml = Inventory(inventory_file; root_url="")
specs = [
":jl:type:`DocumenterInterLinks.InterLinks`",
":jl:method:`DocumenterInterLinks.find_in_interlinks-Tuple{InterLinks, AbstractString}`",
":std:doc:`api/internals`",
# :doc: names should always use unix path separators
]
for spec in specs
@test !isnothing(inventory[spec])
@test !isnothing(inventory_toml[spec])
end
end

@test collect(inventory_toml) == collect(inventory)

end

end

0 comments on commit 1bd05b0

Please sign in to comment.