Skip to content

Commit 1d52fb5

Browse files
committed
fix: error when meta-refresh tag is missing
1 parent 735b92e commit 1d52fb5

File tree

27 files changed

+55
-15
lines changed

27 files changed

+55
-15
lines changed

src/documentertools/canonical_urls.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,11 @@ function update_canonical_links(docs_directory::AbstractString; canonical::Abstr
8383
docs_directory = abspath(docs_directory)
8484
isdir(docs_directory) || throw(ArgumentError("No such directory: $(docs_directory)"))
8585

86-
redirect_index_html_path = joinpath(docs_directory, "index.html")
87-
canonical_path = if isfile(redirect_index_html_path)
88-
redirect_url = get_meta_redirect_url(redirect_index_html_path)
89-
splitpath(normpath(redirect_url))
90-
else
86+
canonical_path = canonical_directory_from_redirect_index_html(docs_directory)
87+
if isnothing(canonical_path)
9188
# canonical_version_from_versions_js returns just a string, but we want to splat
9289
# canonical_path later, so we turn this into a single-element tuple
93-
(canonical_version_from_versions_js(docs_directory),)
90+
canonical_path = (canonical_version_from_versions_js(docs_directory),)
9491
end
9592
canonical_full_root = joinurl(canonical, canonical_path...)
9693
# If we have determined which version should be the canonical version, we can actually
@@ -132,6 +129,7 @@ function canonical_directory_from_redirect_index_html(docs_directory::AbstractSt
132129
redirect_index_html_path = joinpath(docs_directory, "index.html")
133130
isfile(redirect_index_html_path) || return nothing
134131
redirect_url = get_meta_redirect_url(redirect_index_html_path)
132+
isnothing(redirect_url) && return nothing
135133
splitpath(normpath(redirect_url))
136134
end
137135

@@ -189,7 +187,7 @@ function canonical_version_from_versions_js(docs_directory)
189187
# We'll filter out a couple of potential bad cases and issue warnings
190188
filter(versions) do vi
191189
if !vi.path_exists
192-
@warn "update_canonical_links: path does not exists or is not a directory" docs_directory vi
190+
@warn "update_canonical_links: path does not exist or is not a directory" docs_directory vi
193191
return false
194192
end
195193
return true

test/documentertools.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ normalize_newlines(s::AbstractString) = replace(s, "\r\n" => "\n")
77

88
@testset "walkdocs" begin
99
let fileinfos = DocumenterTools.FileInfo[]
10-
rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre")) do fileinfo
10+
rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "simple.pre")) do fileinfo
1111
push!(fileinfos, fileinfo)
1212
@test isabspath(fileinfo.root)
1313
@test isabspath(fileinfo.fullpath)
@@ -20,7 +20,7 @@ normalize_newlines(s::AbstractString) = replace(s, "\r\n" => "\n")
2020

2121
let fileinfos = []
2222
rs = DocumenterTools.walkdocs(
23-
joinpath(FIXTURES, "pre"),
23+
joinpath(FIXTURES, "simple.pre"),
2424
DocumenterTools.isdochtml,
2525
) do fileinfo
2626
push!(fileinfos, fileinfo)
@@ -33,7 +33,10 @@ normalize_newlines(s::AbstractString) = replace(s, "\r\n" => "\n")
3333
@test length(fileinfos) == 6
3434
end
3535

36-
let rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre"), collect = true) do fileinfo
36+
let rs = DocumenterTools.walkdocs(
37+
joinpath(FIXTURES, "simple.pre"),
38+
collect = true,
39+
) do fileinfo
3740
fileinfo.root
3841
end
3942
@test length(rs) == 9
@@ -115,16 +118,16 @@ end
115118
end
116119
end
117120

118-
@testset "update_canonical_links" begin
121+
@testset "update_canonical_links: simple" begin
119122
out = tempname()
120-
cp(joinpath(FIXTURES, "pre"), out)
123+
cp(joinpath(FIXTURES, "simple.pre"), out)
121124
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) ==
122125
["stable"]
123126
DocumenterTools.update_canonical_links(
124127
out;
125128
canonical = "https://example.org/this-is-test",
126129
)
127-
DocumenterTools.walkdocs(joinpath(FIXTURES, "post")) do fileinfo
130+
DocumenterTools.walkdocs(joinpath(FIXTURES, "simple.post")) do fileinfo
128131
post = normalize_newlines(read(fileinfo.fullpath, String))
129132
changed = normalize_newlines(read(joinpath(out, fileinfo.relpath), String))
130133
if changed != post
@@ -137,7 +140,7 @@ end
137140
# directory, remove index.html and instead use versions.js to determine the stable link
138141
# For that we also need to make sure that stable/ is a symlink
139142
out = tempname()
140-
cp(joinpath(FIXTURES, "pre"), out)
143+
cp(joinpath(FIXTURES, "simple.pre"), out)
141144
rm(joinpath(out, "index.html"))
142145
rm(joinpath(out, "stable"), recursive = true)
143146
symlink(joinpath(out, "v0.5.0"), joinpath(out, "stable"))
@@ -158,7 +161,7 @@ end
158161
out;
159162
canonical = "https://example.org/this-is-test",
160163
)
161-
DocumenterTools.walkdocs(joinpath(FIXTURES, "post")) do fileinfo
164+
DocumenterTools.walkdocs(joinpath(FIXTURES, "simple.post")) do fileinfo
162165
# We removed the root /index.html redirect file, so we skip testing it
163166
(fileinfo.relpath == "index.html") && return
164167
# We also don't check the stable/ symlink.
@@ -173,4 +176,17 @@ end
173176
@test changed == post
174177
end
175178
end
179+
180+
# Testing the case where index.html does not have a meta redirect
181+
@testset "update_canonical_links: nometa" begin
182+
out = tempname()
183+
cp(joinpath(FIXTURES, "nometa.pre"), out)
184+
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) === nothing
185+
@test DocumenterTools.canonical_version_from_versions_js(out) == "stable"
186+
# Just
187+
@test DocumenterTools.update_canonical_links(
188+
out;
189+
canonical = "https://example.org/this-is-test",
190+
) === nothing
191+
end
176192
end

test/fixtures/nometa.pre/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!--This file is automatically generated by Documenter.jl-->
2+
<!--The meta tag is missing.-->

test/fixtures/nometa.pre/stable

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.5.0/

test/fixtures/nometa.pre/versions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var DOC_VERSIONS = [
2+
"stable",
3+
"v0.5.0"
4+
];
5+
var DOCUMENTER_NEWEST = "v0.5.0";
6+
var DOCUMENTER_STABLE = "stable";
File renamed without changes.

0 commit comments

Comments
 (0)