Skip to content

Instantly share code, notes, and snippets.

@goerz
Created March 27, 2024 21:54
Show Gist options
  • Save goerz/ea5bb862b57cd8e9b212c445da285b70 to your computer and use it in GitHub Desktop.
Save goerz/ea5bb862b57cd8e9b212c445da285b70 to your computer and use it in GitHub Desktop.
Testing an `objects.inv` inventory file in Julia
# Assumptions
#
# * current working directory is the root directory of the project ("DocInventories") in this case
# * the documentation for the project has been built locally in `docs/build/`
# * the documentation has also been deployed online and is available at the `root_url` hard-coded in the script. Otherwise, do not call `check_url`
# * running on Unix (otherwise: adjust that path separator)
using HTTP
using URIs
using DocInventories
check_url(url) = HTTP.request("GET", url).status == 200
function check_locally(relative_url, fragment)
filename = joinpath("docs", "build", relative_url)
if isfile(filename)
if isempty(fragment)
return true
else
html = read(filename, String)
fragment = URIs.unescapeuri(fragment)
return contains(html, "id=\"$fragment\"")
end
else
return false
end
end
inventory = Inventory("docs/build/objects.inv"; root_url="https://juliadocs.org/DocInventories.jl/stable/")
for item in inventory
url = DocInventories.uri(item; root_url=inventory.root_url)
relative_url = DocInventories.uri(item)
fragment = ""
if contains(url, "#")
url, fragment = split(url, "#")
end
@assert check_url(url)
if contains(relative_url, "#")
relative_url, fragment = split(relative_url, "#")
end
if endswith(relative_url, "/")
relative_url *= "index.html"
end
if isempty(relative_url)
relative_url = "index.html"
end
@show relative_url, fragment
@assert check_locally(relative_url, fragment)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment