Skip to content

Commit 23b2f4e

Browse files
committed
clean up the loop a bit
1 parent 20f1725 commit 23b2f4e

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/documentertools/canonical_urls.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,34 @@ function update_canonical_links(
9393
end
9494
canonical_full_root = joinurl(canonical, canonical_path...)
9595
# If we have determined which version should be the canonical version, we can actually
96-
# go and run update_canonical_links_for_version on each directory.
97-
for filename in readdir(docs_directory)
98-
path = joinpath(docs_directory, filename)
96+
# go and run update_canonical_links_for_version on each directory. First, we'll gather
97+
# up the list of Documenter (or other) directories we actually want to run over.
98+
docs_subdirectory_queue, docs_subdirectories = readdir(docs_directory), []
99+
while !isempty(docs_subdirectory_queue)
100+
docs_subdirectory = popfirst!(docs_subdirectory_queue)
101+
path = joinpath(docs_directory, docs_subdirectory)
99102
# We'll skip all files. This includes files such as index.html, which in this
100103
# directory will likely be the redirect. Also, links should be pointing to other
101104
# versions, so we'll skip them too.
102-
if islink(path) || !isdir(path)
105+
if !isdir(path) || islink(path)
103106
continue
104107
end
105-
# For true directories, we check that siteinfo.js file is present, which is a pretty
106-
# good indicator that it's a proper Documenter build.
107-
if !isfile(joinpath(path, "siteinfo.js"))
108-
# We want to warn if we run across any directories that are not Documenter builds.
109-
# But previews/ is one valid case which may be present and so we shouldn't warn
110-
# for this one.
111-
if filename != "previews"
112-
@warn "update_canonical_links: skipping directory that does not look like a Documenter build" filename docs_directory
113-
end
108+
# Preview directory is should contain other Documenter directories, so we just add
109+
# the subdirectories into the queue and ignore the parent directory itself
110+
if docs_subdirectory == "previews"
111+
append!(docs_subdirectory_queue, joinpath.(docs_subdirectory, readdir(path)))
114112
continue
115113
end
116-
# Finally, we can run update_canonical_links_for_version on the directory.
117-
@debug "Updating canonical URLs for version" docs_directory filename canonical_full_root
114+
# For other directories, we check for the presence of siteinfo.js, and warn if that
115+
# is missing (but we still try to go and update the canonical URLs).
116+
if !isfile(joinpath(path, "siteinfo.js"))
117+
@warn "update_canonical_links: missing siteinfo.js file" path
118+
end
119+
push!(docs_subdirectories, path)
120+
end
121+
# Finally, we can run update_canonical_links_for_version on the directory.
122+
for path in docs_subdirectories
123+
@debug "Updating canonical URLs for a version" path canonical_full_root
118124
update_canonical_links_for_version(path; canonical = canonical_full_root)
119125
end
120126
end

test/documentertools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FIXTURES = joinpath(@__DIR__, "fixtures")
3131
let rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre"), collect=true) do fileinfo
3232
fileinfo.root
3333
end
34-
@test length(rs) == 5
34+
@test length(rs) == 9
3535
@test all(s -> isa(s, String), rs)
3636
end
3737
end

0 commit comments

Comments
 (0)