Skip to content

Commit 4b5fa03

Browse files
authored
Merge pull request #22 from JuliaComputing/sp/better-linking
feat: improve toplevel links if root/index.html does not exist
2 parents 8e59337 + 3cefe69 commit 4b5fa03

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

src/MultiDocumenter.jl

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,32 @@ function make_output_structure(docs::Vector{MultiDocRef}, prettyurls)
181181
return dir
182182
end
183183

184+
function insert_multidocref_html!(navitems, doc, dir, thispagepath, prettyurls)
185+
path = joinpath(dir, doc.path)
186+
if !isfile(joinpath(path, "index.html"))
187+
stable = joinpath(path, "stable")
188+
dev = joinpath(path, "dev")
189+
if isfile(joinpath(stable, "index.html"))
190+
path = stable
191+
elseif isfile(joinpath(dev, "index.html"))
192+
path = dev
193+
end
194+
end
195+
rp = relpath(path, thispagepath)
196+
a = Gumbo.HTMLElement{:a}(
197+
[],
198+
navitems,
199+
Dict(
200+
"href" => string(rp, prettyurls ? "/" : "/index.html"),
201+
"class" =>
202+
startswith(thispagepath, joinpath(dir, doc.path, "")) ? # need to force a trailing pathsep here
203+
"nav-link active nav-item" : "nav-link nav-item",
204+
),
205+
)
206+
push!(a.children, Gumbo.HTMLText(a, doc.name))
207+
push!(navitems.children, a)
208+
end
209+
184210
function make_global_nav(
185211
dir,
186212
docs::Vector,
@@ -221,19 +247,7 @@ function make_global_nav(
221247

222248
for doc in docs
223249
if doc isa MultiDocRef
224-
rp = relpath(joinpath(dir, doc.path), thispagepath)
225-
a = Gumbo.HTMLElement{:a}(
226-
[],
227-
navitems,
228-
Dict(
229-
"href" => string(rp, prettyurls ? "/" : "/index.html"),
230-
"class" =>
231-
startswith(thispagepath, joinpath(dir, doc.path, "")) ? # need to force a trailing pathsep here
232-
"nav-link active nav-item" : "nav-link nav-item",
233-
),
234-
)
235-
push!(a.children, Gumbo.HTMLText(a, doc.name))
236-
push!(navitems.children, a)
250+
insert_multidocref_html!(navitems, doc, dir, thispagepath, prettyurls)
237251
else # doc isa DropdownNav
238252
div = Gumbo.HTMLElement{:div}(
239253
[],
@@ -248,20 +262,8 @@ function make_global_nav(
248262
push!(navitems.children, div)
249263

250264
for doc in doc.children
251-
rp = relpath(joinpath(dir, doc.path), thispagepath)
252265
li = Gumbo.HTMLElement{:li}([], ul, Dict())
253-
a = Gumbo.HTMLElement{:a}(
254-
[],
255-
li,
256-
Dict(
257-
"href" => string(rp, prettyurls ? "/" : "/index.html"),
258-
"class" =>
259-
startswith(thispagepath, joinpath(dir, doc.path, "")) ? # need to force a trailing pathsep here
260-
"nav-link active nav-item" : "nav-link nav-item",
261-
),
262-
)
263-
push!(a.children, Gumbo.HTMLText(a, doc.name))
264-
push!(li.children, a)
266+
insert_multidocref_html!(li, doc, dir, thispagepath, prettyurls)
265267
push!(ul.children, li)
266268
end
267269
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ using Test
5959
@test !occursin("/inf/dev/", store_content)
6060
end
6161

62-
# rm(outpath, recursive=true, force=true)
62+
rm(outpath, recursive=true, force=true)
6363
rm(clonedir, recursive=true, force=true)
6464
end

0 commit comments

Comments
 (0)