Created
March 27, 2024 21:54
-
-
Save goerz/ea5bb862b57cd8e9b212c445da285b70 to your computer and use it in GitHub Desktop.
Testing an `objects.inv` inventory file in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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