Skip to content

Commit 39a05f5

Browse files
authored
Merge pull request #33 from JuliaComputing/sp/better-non-documenter-compat
feat: improve compat with non-documenter pages
2 parents 4b79782 + 5fd8e64 commit 39a05f5

File tree

10 files changed

+103
-83
lines changed

10 files changed

+103
-83
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1313

1414
[compat]
1515
AbstractTrees = "0.4"
16-
Gumbo = "0.8"
16+
Gumbo = "0.8.2"
1717
HypertextLiteral = "0.9"
1818
JSON = "0.20,0.21"
1919
NodeJS = "1"

assets/default/flexsearch.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
border-radius: 3.2px;
2020
color: #999;
2121
background-color: unset;
22-
height: 1.8rem;
22+
height: 28px;
2323
font-family: Glober;
2424
width: 20em;
2525
font-size: 14px;
@@ -92,6 +92,11 @@
9292
display: block;
9393
overflow: hidden;
9494
text-overflow: ellipsis;
95+
color: black;
96+
}
97+
98+
.theme--documenter-dark #multi-page-nav .suggestion a {
99+
color: white;
95100
}
96101

97102
#multi-page-nav .suggestion a:hover,

assets/default/flexsearch_integration.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,39 @@
1313
},
1414
});
1515

16-
let importDone = null
16+
let successfullyLoadedIndex = null
1717

1818
function loadIndex(flexsearchIdx) {
1919
const input = document.getElementById('search-input')
2020
input.setAttribute('placeholder', 'Loading...')
21-
importDone = false
21+
successfullyLoadedIndex = false
2222
const keys = ['content.cfg', 'content.ctx', 'content.map', 'reg', 'store']
23-
for (const key of keys) {
24-
fetch('/search-data/' + key + '.json').then(r => {
25-
if (r.ok) {
26-
r.json().then(idx => {
27-
flexsearchIdx.import(key, idx)
28-
if (key === keys[keys.length - 1]) {
29-
setTimeout(() => {
30-
importDone = true
31-
input.setAttribute('placeholder', 'Search...')
32-
}, 100)
33-
}
34-
})
35-
} else {
36-
input.setAttribute('placeholder', 'Error loading search index.')
37-
}
23+
const promises = keys.map(key => {
24+
return new Promise((resolve, reject) => {
25+
fetch('/search-data/' + key + '.json').then(r => {
26+
if (r && r.ok) {
27+
r.json().then(idx => {
28+
flexsearchIdx.import(key, idx)
29+
resolve()
30+
}).catch(() => {
31+
reject()
32+
})
33+
} else {
34+
reject()
35+
}
36+
}).catch(() => {
37+
reject()
38+
})
3839
})
39-
}
40+
})
41+
42+
Promise.all(promises).then(() => {
43+
input.setAttribute('placeholder', 'Search...')
44+
successfullyLoadedIndex = true
45+
}).catch(() => {
46+
input.setAttribute('placeholder', 'Error loading search data...')
47+
successfullyLoadedIndex = false
48+
})
4049
}
4150

4251
function registerSearchListener() {
@@ -46,9 +55,9 @@
4655
let lastQuery = ''
4756

4857
function runSearch() {
49-
if (importDone === null) {
58+
if (successfullyLoadedIndex === null) {
5059
loadIndex(flexsearchIdx)
51-
} else if (importDone === false) {
60+
} else if (successfullyLoadedIndex === false) {
5261
return
5362
}
5463
const query = input.value

assets/default/multidoc.css

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ html {
88
height: var(--navbar-height);
99
z-index: 10;
1010
padding: 0 1rem;
11-
position: fixed;
11+
position: sticky;
1212
display: flex;
1313
top: 0;
1414
background-color: #282f2f;
@@ -25,15 +25,19 @@ html {
2525
display: none;
2626
margin-left: auto;
2727
font-size: 24px;
28-
color: white;
29-
margin-left: auto;
30-
line-height: var(--navbar-height);
28+
height: var(--navbar-height);
3129
padding: 0;
30+
fill: white;
31+
cursor: pointer;
32+
border: none;
33+
background: none;
34+
padding-inline: none;
3235
}
3336

34-
#multi-page-nav #multidoc-toggler:before {
35-
content: "\f0c9";
36-
font-family: "Font Awesome 5 Free";
37+
#multi-page-nav #multidoc-toggler > svg {
38+
line-height: unset;
39+
width: 24px;
40+
height: 24px;
3741
}
3842

3943
#multi-page-nav>* {
@@ -67,6 +71,7 @@ html {
6771
border: none;
6872
text-align: left;
6973
background: none;
74+
padding: 0 12px;
7075
}
7176

7277
#multi-page-nav .nav-expanded .dropdown-label {
@@ -132,6 +137,9 @@ html {
132137

133138
#multi-page-nav .nav-mega-dropdown-container .column-header {
134139
color: #fff;
140+
font-size: 16px;
141+
padding: 5px;
142+
margin: 0;
135143
text-transform: uppercase;
136144
}
137145

@@ -165,12 +173,11 @@ html {
165173
font-weight: bold;
166174
}
167175

168-
/* Documenter css tweaks */
169-
170-
#documenter .docs-main header.docs-navbar {
171-
top: var(--navbar-height);
176+
#multi-page-nav .column-content {
177+
padding: 0;
172178
}
173179

180+
/* Documenter css tweaks */
174181
.docs-sidebar {
175182
padding-top: calc(var(--navbar-height) + 1rem) !important;
176183
}
@@ -179,13 +186,6 @@ html {
179186
top: 0;
180187
}
181188

182-
@media screen and (min-width: 1056px) {
183-
#documenter {
184-
margin-top: calc(var(--navbar-height)) !important;
185-
}
186-
}
187-
188-
/* headroom.js for the multi-page navbar */
189189
@media screen and (max-width: 1055px) {
190190
#multi-page-nav {
191191
position: sticky;

assets/default/multidoc_injector.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function multidocInjector() {
2+
document
3+
.getElementById("multidoc-toggler")
4+
.addEventListener("click", function () {
5+
document.getElementById("nav-items").classList.toggle("hidden-on-mobile");
6+
});
7+
document.body.addEventListener("click", function (ev) {
8+
const thisIsExpanded = ev.target.matches(".nav-expanded > .dropdown-label");
9+
if (!ev.target.matches(".nav-dropdown-container")) {
10+
Array.prototype.forEach.call(
11+
document.getElementsByClassName("dropdown-label"),
12+
function (el) {
13+
el.parentElement.classList.remove("nav-expanded");
14+
}
15+
);
16+
}
17+
if (!thisIsExpanded && ev.target.matches(".dropdown-label")) {
18+
ev.target.parentElement.classList.add("nav-expanded");
19+
}
20+
});
21+
}
22+
23+
if (
24+
document.readyState === "complete" ||
25+
document.readyState === "interactive"
26+
) {
27+
// call on next available tick
28+
setTimeout(multidocInjector, 1);
29+
} else {
30+
document.addEventListener("DOMContentLoaded", multidocInjector);
31+
}

assets/multidoc_injector.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/MultiDocumenter.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
9494
- `assets_dir` is copied into `outdir/assets`
9595
- `brand_image` is a `BrandImage(path, imgpath)`, which is rendered as the leftmost
9696
item in the global navigation
97-
- `custom_stylesheets` is a `Vector{String}` of stylesheets injected into each page.
98-
- `custom_scripts` is a `Vector{String}` of scripts injected into each page.
97+
- `custom_stylesheets` is a `Vector{String}` of relative stylesheet URLs injected into each page.
98+
- `custom_scripts` is a `Vector{String}` of relative script URLs injected into each page.
9999
- `search_engine` inserts a global search bar if not `false`. See [`SearchConfig`](@ref) for more details.
100100
- `prettyurls` removes all `index.html` suffixes from links in the global navigation.
101101
"""
@@ -216,7 +216,11 @@ function make_global_nav(
216216
$([render(doc, dir, thispagepath, prettyurls) for doc in docs])
217217
$(search_engine.engine.render())
218218
</div>
219-
<a id="multidoc-toggler"></a>
219+
<button id="multidoc-toggler">
220+
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
221+
<path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"></path>
222+
</svg>
223+
</button>
220224
</nav>
221225
"""
222226

@@ -233,7 +237,7 @@ function make_global_stylesheet(custom_stylesheets, path)
233237
Dict(
234238
"rel" => "stylesheet",
235239
"type" => "text/css",
236-
"href" => joinpath(path, stylesheet),
240+
"href" => string(path, "/", stylesheet),
237241
),
238242
)
239243
push!(out, style)
@@ -250,7 +254,7 @@ function make_global_scripts(custom_scripts, path)
250254
[],
251255
Gumbo.NullNode(),
252256
Dict(
253-
"src" => joinpath(path, script),
257+
"src" => string(path, "/", script),
254258
"type" => "text/javascript",
255259
"charset" => "utf-8",
256260
),
@@ -281,16 +285,11 @@ function inject_styles_and_global_navigation(
281285
search_engine.engine.inject_styles!(custom_stylesheets)
282286
end
283287
pushfirst!(custom_stylesheets, joinpath("assets", "default", "multidoc.css"))
288+
pushfirst!(custom_scripts, joinpath("assets", "default", "multidoc_injector.js"))
284289

285290
@sync for (root, _, files) in walkdir(dir)
286291
for file in files
287292
path = joinpath(root, file)
288-
if file == "documenter.js"
289-
open(path, "a") do io
290-
println(io, js_injector())
291-
end
292-
continue
293-
end
294293

295294
endswith(file, ".html") || continue
296295

src/renderers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ end
5454
function render(doc::Column, dir, thispagepath, prettyurls)
5555
return @htl """
5656
<div class="nav-mega-column">
57-
<h5 class="column-header">$(doc.name)</h5>
57+
<div class="column-header">$(doc.name)</div>
5858
<ul class="column-content">
5959
$([render(doc, dir, thispagepath, prettyurls) for doc in doc.children])
6060
</ul>

src/search/flexsearch.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function add_to_index!(index, ref, file)
7575
title = Gumbo.text(el)
7676
doc.title = first(split(title, " · "))
7777
end
78-
if Gumbo.tag(el) == :article && Gumbo.getattr(el, "class", "") == "content"
78+
if Gumbo.tag(el) == :article
7979
add_fragment(doc, el)
8080
break
8181
end

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ using Test
3333
name = "JuliaInterpreter",
3434
giturl = "https://github.com/JuliaDebug/JuliaInterpreter.jl.git",
3535
),
36+
MultiDocumenter.MultiDocRef(
37+
upstream = joinpath(clonedir, "Lux"),
38+
path = "lux",
39+
name = "Lux",
40+
giturl = "https://github.com/avik-pal/Lux.jl",
41+
),
3642
]),
3743
MultiDocumenter.Column("Column 2", [
3844
MultiDocumenter.MultiDocRef(

0 commit comments

Comments
 (0)