Skip to content

Commit 015ee31

Browse files
committed
fix formatting
1 parent 23b2f4e commit 015ee31

File tree

5 files changed

+95
-59
lines changed

5 files changed

+95
-59
lines changed

src/MultiDocumenter.jl

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ using HypertextLiteral
55
import Git: git
66

77
module DocumenterTools
8-
import Gumbo, AbstractTrees
9-
include("documentertools/walkdocs.jl")
10-
include("documentertools/canonical_urls.jl")
8+
import Gumbo, AbstractTrees
9+
include("documentertools/walkdocs.jl")
10+
include("documentertools/canonical_urls.jl")
1111
end
1212

1313
"""
@@ -38,7 +38,14 @@ struct MultiDocRef
3838
branch::String
3939
end
4040

41-
function MultiDocRef(; upstream, name, path, giturl = "", branch = "gh-pages", fix_canonical_url=true)
41+
function MultiDocRef(;
42+
upstream,
43+
name,
44+
path,
45+
giturl = "",
46+
branch = "gh-pages",
47+
fix_canonical_url = true,
48+
)
4249
MultiDocRef(upstream, path, name, fix_canonical_url, giturl, branch)
4350
end
4451

@@ -130,14 +137,19 @@ function make(
130137
prettyurls = true,
131138
rootpath = "/",
132139
hide_previews = true,
133-
canonical::Union{AbstractString, Nothing} = nothing,
140+
canonical::Union{AbstractString,Nothing} = nothing,
134141
)
135142
maybe_clone(flatten_multidocrefs(docs))
136143

137144
if !isnothing(canonical)
138145
canonical = rstrip(canonical, '/')
139146
end
140-
dir = make_output_structure(flatten_multidocrefs(docs), prettyurls, hide_previews; canonical)
147+
dir = make_output_structure(
148+
flatten_multidocrefs(docs),
149+
prettyurls,
150+
hide_previews;
151+
canonical,
152+
)
141153
out_assets = joinpath(dir, "assets")
142154
if assets_dir !== nothing && isdir(assets_dir)
143155
cp(assets_dir, out_assets)
@@ -210,9 +222,11 @@ function maybe_clone(docs::Vector{MultiDocRef})
210222
end
211223

212224
function make_output_structure(
213-
docs::Vector{MultiDocRef}, prettyurls, hide_previews;
214-
canonical::Union{AbstractString, Nothing}
215-
)
225+
docs::Vector{MultiDocRef},
226+
prettyurls,
227+
hide_previews;
228+
canonical::Union{AbstractString,Nothing},
229+
)
216230
dir = mktempdir()
217231

218232
for doc in docs
@@ -231,7 +245,7 @@ function make_output_structure(
231245
rm(previewpath, recursive = true)
232246
end
233247

234-
fix_canonical_url!(doc; canonical, root_dir=dir)
248+
fix_canonical_url!(doc; canonical, root_dir = dir)
235249
end
236250

237251
open(joinpath(dir, "index.html"), "w") do io

src/canonical.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# This files contains the functions used to implement the canonical URL
22
# update functionality.
33
function fix_canonical_url!(
4-
doc::MultiDocRef; canonical::Union{AbstractString, Nothing}, root_dir::AbstractString
5-
)
4+
doc::MultiDocRef;
5+
canonical::Union{AbstractString,Nothing},
6+
root_dir::AbstractString,
7+
)
68
# If the user didn't set `canonical`, then we don't need to do anything
79
isnothing(canonical) && return nothing
810
# The user can also disable the canonical URL fixing on a per-package basis
@@ -12,9 +14,10 @@ function fix_canonical_url!(
1214
try
1315
DocumenterTools.update_canonical_links(
1416
documenter_directory_root;
15-
canonical = join((canonical, doc.path), '/')
17+
canonical = join((canonical, doc.path), '/'),
1618
)
1719
catch e
18-
@error "Unable to update canonical URLs for this package" doc exception = (e, catch_backtrace())
20+
@error "Unable to update canonical URLs for this package" doc exception =
21+
(e, catch_backtrace())
1922
end
2023
end

src/documentertools/canonical_urls.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
specifying the root of the canonical URL.
1717
"""
1818
function update_canonical_links_for_version(
19-
docs_directory::AbstractString;
20-
canonical::AbstractString
21-
)
19+
docs_directory::AbstractString;
20+
canonical::AbstractString,
21+
)
2222
canonical = rstrip(canonical, '/')
2323

2424
walkdocs(docs_directory, isdochtml) do fileinfo
@@ -49,10 +49,9 @@ function update_canonical_links_for_version(
4949
e isa Gumbo.HTMLElement || continue
5050
Gumbo.tag(e) == :head || continue
5151
canonical_href_element = Gumbo.HTMLElement{:link}(
52-
[], e, Dict(
53-
"rel" => "canonical",
54-
"href" => new_canonical_href,
55-
)
52+
[],
53+
e,
54+
Dict("rel" => "canonical", "href" => new_canonical_href),
5655
)
5756
push!(e.children, canonical_href_element)
5857
@debug "update_canonical_links_for_version: added new canonical_href" new_canonical_href fileinfo.relpath
@@ -69,17 +68,17 @@ function update_canonical_links_for_version(
6968
end
7069
end
7170

72-
is_canonical_element(e) = (e isa Gumbo.HTMLElement) && (Gumbo.tag(e) == :link) && (Gumbo.getattr(e, "rel", nothing) == "canonical")
71+
is_canonical_element(e) =
72+
(e isa Gumbo.HTMLElement) &&
73+
(Gumbo.tag(e) == :link) &&
74+
(Gumbo.getattr(e, "rel", nothing) == "canonical")
7375
joinurl(ps::AbstractString...) = join(ps, '/')
7476

7577
"""
7678
Takes the multi-versioned Documenter site in `docs_directory` and updates the HTML canonical URLs
7779
to point to `canonical`.
7880
"""
79-
function update_canonical_links(
80-
docs_directory::AbstractString;
81-
canonical::AbstractString
82-
)
81+
function update_canonical_links(docs_directory::AbstractString; canonical::AbstractString)
8382
canonical = rstrip(canonical, '/')
8483
docs_directory = abspath(docs_directory)
8584
isdir(docs_directory) || throw(ArgumentError("No such directory: $(docs_directory)"))
@@ -144,12 +143,14 @@ function get_meta_redirect_url(indexhtml_path::AbstractString)
144143
Gumbo.getattr(e, "http-equiv", nothing) == "refresh" || continue
145144
content = Gumbo.getattr(e, "content", nothing)
146145
if isnothing(content)
147-
@warn "<meta http-equiv=\"refresh\" ...> with no content attribute" path = indexhtml_path
146+
@warn "<meta http-equiv=\"refresh\" ...> with no content attribute" path =
147+
indexhtml_path
148148
continue
149149
end
150150
m = match(r"[0-9]+;\s*url=(.*)", content)
151151
if isnothing(m)
152-
@warn "Unable to parse content value of <meta http-equiv=\"refresh\" ...>" content path = indexhtml_path
152+
@warn "Unable to parse content value of <meta http-equiv=\"refresh\" ...>" content path =
153+
indexhtml_path
153154
continue
154155
end
155156
return m.captures[1]
@@ -161,7 +162,8 @@ function canonical_version_from_versions_js(docs_directory)
161162
isdir(docs_directory) || throw(ArgumentError("Not a directory: $(docs_directory)"))
162163
# Try to extract the list of versions from versions.js
163164
versions_js = joinpath(docs_directory, "versions.js")
164-
isfile(versions_js) || throw(ArgumentError("versions.js is missing in $(docs_directory)"))
165+
isfile(versions_js) ||
166+
throw(ArgumentError("versions.js is missing in $(docs_directory)"))
165167
versions = map(extract_versions_list(versions_js)) do version_str
166168
isversion, version_number = if occursin(Base.VERSION_REGEX, version_str)
167169
true, VersionNumber(version_str)
@@ -212,7 +214,9 @@ function canonical_version_from_versions_js(docs_directory)
212214
_, idx = findmax(first, version_symlinks)
213215
version_symlinks[idx][2]
214216
elseif length(non_version_symlinks) > 1
215-
error("Unable to determine the canonical path. Found multiple non-version symlinks.\n$(non_version_symlinks)")
217+
error(
218+
"Unable to determine the canonical path. Found multiple non-version symlinks.\n$(non_version_symlinks)",
219+
)
216220
else
217221
only(non_version_symlinks)
218222
end

src/documentertools/walkdocs.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Objects of this type are passed as arguments to the callback of the [`walkdocs`]
1313
See [`walkdocs`](@ref) for information on how to interpret the docstrings.
1414
"""
1515
Base.@kwdef struct FileInfo
16-
root :: String
17-
filename :: String
18-
relpath :: String
19-
fullpath :: String
16+
root::String
17+
filename::String
18+
relpath::String
19+
fullpath::String
2020
end
2121

2222
"""
@@ -56,7 +56,7 @@ walkdocs(directory_root, filter = isdochtml) do fileinfo
5656
end
5757
```
5858
"""
59-
function walkdocs(f, dir::AbstractString, filter_cb = _ -> true; collect::Bool=false)
59+
function walkdocs(f, dir::AbstractString, filter_cb = _ -> true; collect::Bool = false)
6060
hasmethod(f, (FileInfo,)) || throw(MethodError(f, (FileInfo,)))
6161
hasmethod(filter_cb, (FileInfo,)) || throw(MethodError(filter_cb, (FileInfo,)))
6262

test/documentertools.jl

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ FIXTURES = joinpath(@__DIR__, "fixtures")
1717
end
1818

1919
let fileinfos = []
20-
rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre"), DocumenterTools.isdochtml) do fileinfo
20+
rs = DocumenterTools.walkdocs(
21+
joinpath(FIXTURES, "pre"),
22+
DocumenterTools.isdochtml,
23+
) do fileinfo
2124
push!(fileinfos, fileinfo)
2225
@test isabspath(fileinfo.root)
2326
@test isabspath(fileinfo.fullpath)
@@ -28,7 +31,7 @@ FIXTURES = joinpath(@__DIR__, "fixtures")
2831
@test length(fileinfos) == 6
2932
end
3033

31-
let rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre"), collect=true) do fileinfo
34+
let rs = DocumenterTools.walkdocs(joinpath(FIXTURES, "pre"), collect = true) do fileinfo
3235
fileinfo.root
3336
end
3437
@test length(rs) == 9
@@ -57,18 +60,22 @@ end
5760

5861
@testset "canonical_urls" begin
5962
@testset "parsing versions.js" begin
60-
withfiles("versions.js" => """
61-
var DOC_VERSIONS = [
62-
"stable",
63-
"v0.27",
64-
"v0.1",
65-
"dev",
66-
];
67-
""",
68-
"v0.27" => :dir, "v0.1" => :dir, "dev" => :dir,
63+
withfiles(
64+
"versions.js" => """
65+
var DOC_VERSIONS = [
66+
"stable",
67+
"v0.27",
68+
"v0.1",
69+
"dev",
70+
];
71+
""",
72+
"v0.27" => :dir,
73+
"v0.1" => :dir,
74+
"dev" => :dir,
6975
"stable" => (:symlink, "v0.27"),
7076
) do path
71-
@test DocumenterTools.extract_versions_list(joinpath(path, "versions.js")) == ["stable", "v0.27", "v0.1", "dev"]
77+
@test DocumenterTools.extract_versions_list(joinpath(path, "versions.js")) ==
78+
["stable", "v0.27", "v0.1", "dev"]
7279
@test DocumenterTools.canonical_version_from_versions_js(path) == "stable"
7380
end
7481

@@ -78,35 +85,43 @@ end
7885
"v2",
7986
"dev",
8087
];
81-
""",
82-
"v1" => :dir, "v2" => :dir, "dev" => :dir,
83-
) do path
84-
@test DocumenterTools.extract_versions_list(joinpath(path, "versions.js")) == ["v1", "v2", "dev"]
88+
""", "v1" => :dir, "v2" => :dir, "dev" => :dir) do path
89+
@test DocumenterTools.extract_versions_list(joinpath(path, "versions.js")) ==
90+
["v1", "v2", "dev"]
8591
@test DocumenterTools.canonical_version_from_versions_js(path) == "v2"
8692
end
8793
end
8894

8995
@testset "parsing redirect index.html" begin
9096
mktempdir() do path
91-
@test DocumenterTools.canonical_directory_from_redirect_index_html(path) === nothing
97+
@test DocumenterTools.canonical_directory_from_redirect_index_html(path) ===
98+
nothing
9299
end
93100

94101
mktempdir() do path
95102
file = joinpath(path, "index.html")
96-
write(file, """
97-
<!--This file is automatically generated by Documenter.jl-->
98-
<meta http-equiv="refresh" content="0; url=./stable/"/>
99-
""")
103+
write(
104+
file,
105+
"""
106+
<!--This file is automatically generated by Documenter.jl-->
107+
<meta http-equiv="refresh" content="0; url=./stable/"/>
108+
""",
109+
)
100110
@test DocumenterTools.get_meta_redirect_url(file) == "./stable/"
101-
@test DocumenterTools.canonical_directory_from_redirect_index_html(path) == ["stable"]
111+
@test DocumenterTools.canonical_directory_from_redirect_index_html(path) ==
112+
["stable"]
102113
end
103114
end
104115

105116
@testset "update_canonical_links" begin
106117
out = tempname()
107118
cp(joinpath(FIXTURES, "pre"), out)
108-
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) == ["stable"]
109-
DocumenterTools.update_canonical_links(out; canonical = "https://example.org/this-is-test")
119+
@test DocumenterTools.canonical_directory_from_redirect_index_html(out) ==
120+
["stable"]
121+
DocumenterTools.update_canonical_links(
122+
out;
123+
canonical = "https://example.org/this-is-test",
124+
)
110125
DocumenterTools.walkdocs(joinpath(FIXTURES, "post")) do fileinfo
111126
post = read(fileinfo.fullpath, String)
112127
changed = read(joinpath(out, fileinfo.relpath), String)

0 commit comments

Comments
 (0)