Skip to content

Commit

Permalink
Fix a bug in update_canonical_links (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi authored Sep 13, 2023
1 parent 7f60411 commit 4085f74
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/documentertools/canonical_urls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function update_canonical_links(docs_directory::AbstractString; canonical::Abstr
redirect_url = get_meta_redirect_url(redirect_index_html_path)
splitpath(normpath(redirect_url))
else
canonical_version_from_versions_js(docs_directory)
# canonical_version_from_versions_js returns just a string, but we want to splat
# canonical_path later, so we turn this into a single-element tuple
(canonical_version_from_versions_js(docs_directory),)
end
canonical_full_root = joinurl(canonical, canonical_path...)
# If we have determined which version should be the canonical version, we can actually
Expand Down Expand Up @@ -201,7 +203,6 @@ function canonical_version_from_versions_js(docs_directory)
if isempty(versions)
error("Unable to determine the canonical path. Found no version directories")
end

non_version_symlinks = filter(vi -> !vi.isversion && vi.symlink, versions)
canonical_version = if isempty(non_version_symlinks)
# We didn't find any non-version symlinks, so we'll try to find the vN directory now
Expand Down
40 changes: 40 additions & 0 deletions test/documentertools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,45 @@ end
end
@test changed == post
end

# We take the fixtures/pre directory, but copy it over into a temporary
# directory, remove index.html and instead use versions.js to determine the stable link
# For that we also need to make sure that stable/ is a symlink
out = tempname()
cp(joinpath(FIXTURES, "pre"), out)
rm(joinpath(out, "index.html"))
rm(joinpath(out, "stable"), recursive = true)
symlink(joinpath(out, "v0.5.0"), joinpath(out, "stable"))
open(joinpath(out, "versions.js"), write = true) do io
versions_js = """
var DOC_VERSIONS = [
"stable",
"v0.5.0",
];
var DOCUMENTER_NEWEST = "v0.5.0";
var DOCUMENTER_STABLE = "stable";
"""
write(io, versions_js)
end
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) === nothing
@test DocumenterTools.canonical_version_from_versions_js(out) == "stable"
DocumenterTools.update_canonical_links(
out;
canonical = "https://example.org/this-is-test",
)
DocumenterTools.walkdocs(joinpath(FIXTURES, "post")) do fileinfo
# We removed the root /index.html redirect file, so we skip testing it
(fileinfo.relpath == "index.html") && return
# We also don't check the stable/ symlink.
# Note: the regex is necessary to handle Windows path separators.
startswith(fileinfo.relpath, r"stable[\\/]") && return
# Compare the file contents for the rest of the files:
post = normalize_newlines(read(fileinfo.fullpath, String))
changed = normalize_newlines(read(joinpath(out, fileinfo.relpath), String))
if changed != post
@error "update_canonical_links: change and post not matching" out fileinfo
end
@test changed == post
end
end
end

0 comments on commit 4085f74

Please sign in to comment.