Skip to content

Commit 4085f74

Browse files
authored
Fix a bug in update_canonical_links (#69)
1 parent 7f60411 commit 4085f74

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/documentertools/canonical_urls.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ function update_canonical_links(docs_directory::AbstractString; canonical::Abstr
8888
redirect_url = get_meta_redirect_url(redirect_index_html_path)
8989
splitpath(normpath(redirect_url))
9090
else
91-
canonical_version_from_versions_js(docs_directory)
91+
# canonical_version_from_versions_js returns just a string, but we want to splat
92+
# canonical_path later, so we turn this into a single-element tuple
93+
(canonical_version_from_versions_js(docs_directory),)
9294
end
9395
canonical_full_root = joinurl(canonical, canonical_path...)
9496
# If we have determined which version should be the canonical version, we can actually
@@ -201,7 +203,6 @@ function canonical_version_from_versions_js(docs_directory)
201203
if isempty(versions)
202204
error("Unable to determine the canonical path. Found no version directories")
203205
end
204-
205206
non_version_symlinks = filter(vi -> !vi.isversion && vi.symlink, versions)
206207
canonical_version = if isempty(non_version_symlinks)
207208
# We didn't find any non-version symlinks, so we'll try to find the vN directory now

test/documentertools.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,45 @@ end
132132
end
133133
@test changed == post
134134
end
135+
136+
# We take the fixtures/pre directory, but copy it over into a temporary
137+
# directory, remove index.html and instead use versions.js to determine the stable link
138+
# For that we also need to make sure that stable/ is a symlink
139+
out = tempname()
140+
cp(joinpath(FIXTURES, "pre"), out)
141+
rm(joinpath(out, "index.html"))
142+
rm(joinpath(out, "stable"), recursive = true)
143+
symlink(joinpath(out, "v0.5.0"), joinpath(out, "stable"))
144+
open(joinpath(out, "versions.js"), write = true) do io
145+
versions_js = """
146+
var DOC_VERSIONS = [
147+
"stable",
148+
"v0.5.0",
149+
];
150+
var DOCUMENTER_NEWEST = "v0.5.0";
151+
var DOCUMENTER_STABLE = "stable";
152+
"""
153+
write(io, versions_js)
154+
end
155+
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) === nothing
156+
@test DocumenterTools.canonical_version_from_versions_js(out) == "stable"
157+
DocumenterTools.update_canonical_links(
158+
out;
159+
canonical = "https://example.org/this-is-test",
160+
)
161+
DocumenterTools.walkdocs(joinpath(FIXTURES, "post")) do fileinfo
162+
# We removed the root /index.html redirect file, so we skip testing it
163+
(fileinfo.relpath == "index.html") && return
164+
# We also don't check the stable/ symlink.
165+
# Note: the regex is necessary to handle Windows path separators.
166+
startswith(fileinfo.relpath, r"stable[\\/]") && return
167+
# Compare the file contents for the rest of the files:
168+
post = normalize_newlines(read(fileinfo.fullpath, String))
169+
changed = normalize_newlines(read(joinpath(out, fileinfo.relpath), String))
170+
if changed != post
171+
@error "update_canonical_links: change and post not matching" out fileinfo
172+
end
173+
@test changed == post
174+
end
135175
end
136176
end

0 commit comments

Comments
 (0)