@@ -20,17 +20,26 @@ struct MultiDocRef
20
20
21
21
path:: String
22
22
name:: String
23
+
24
+ # these are not actually used internally
25
+ giturl:: String
26
+ branch:: String
27
+ end
28
+
29
+ function MultiDocRef (; upstream, name, path, giturl = " " , branch = " gh-pages" )
30
+ MultiDocRef (upstream, path, name, giturl, branch)
31
+ end
32
+
33
+ struct DropdownNav
34
+ name:: String
35
+ children:: Vector{MultiDocRef}
23
36
end
24
37
25
38
struct BrandImage
26
39
path:: String
27
40
imagepath:: String
28
41
end
29
42
30
- function MultiDocRef (; upstream, name, path)
31
- MultiDocRef (upstream, path, name)
32
- end
33
-
34
43
function walk_outputs (f, root, docs:: Vector{MultiDocRef} , dirs:: Vector{String} )
35
44
for ref in docs
36
45
p = joinpath (root, ref. path)
@@ -78,16 +87,17 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
78
87
"""
79
88
function make (
80
89
outdir,
81
- docs:: Vector{MultiDocRef} ;
90
+ docs:: Vector ;
82
91
assets_dir = nothing ,
83
92
brand_image:: Union{Nothing,BrandImage} = nothing ,
84
93
custom_stylesheets = [],
85
94
custom_scripts = [],
86
95
search_engine = DEFAULT_ENGINE,
87
- prettyurls = true
96
+ prettyurls = true ,
88
97
)
98
+ maybe_clone (flatten_multidocrefs (docs))
89
99
90
- dir = make_output_structure (docs, prettyurls)
100
+ dir = make_output_structure (flatten_multidocrefs ( docs) , prettyurls)
91
101
out_assets = joinpath (dir, " assets" )
92
102
if assets_dir != = nothing && isdir (assets_dir)
93
103
cp (assets_dir, out_assets)
@@ -109,11 +119,11 @@ function make(
109
119
custom_stylesheets,
110
120
custom_scripts,
111
121
search_engine,
112
- prettyurls
122
+ prettyurls,
113
123
)
114
124
115
125
if search_engine != false
116
- search_engine. engine. build_search_index (dir, docs, search_engine)
126
+ search_engine. engine. build_search_index (dir, flatten_multidocrefs ( docs) , search_engine)
117
127
end
118
128
119
129
cp (dir, outdir; force = true )
@@ -122,7 +132,30 @@ function make(
122
132
return outdir
123
133
end
124
134
125
- function make_output_structure (docs:: Vector , prettyurls)
135
+ function flatten_multidocrefs (docs:: Vector )
136
+ out = MultiDocRef[]
137
+ for doc in docs
138
+ if doc isa MultiDocRef
139
+ push! (out, doc)
140
+ else
141
+ for doc in doc. children
142
+ push! (out, doc)
143
+ end
144
+ end
145
+ end
146
+ out
147
+ end
148
+
149
+ function maybe_clone (docs:: Vector{MultiDocRef} )
150
+ for doc in docs
151
+ if ! isdir (doc. upstream)
152
+ @info " Upstream at $(doc. upstream) does not exist. `git clone`ing `$(doc. giturl) #$(doc. branch) `"
153
+ run (` git clone --depth 1 $(doc. giturl) --branch $(doc. branch) --single-branch $(doc. upstream) ` )
154
+ end
155
+ end
156
+ end
157
+
158
+ function make_output_structure (docs:: Vector{MultiDocRef} , prettyurls)
126
159
dir = mktempdir ()
127
160
128
161
for doc in docs
@@ -131,7 +164,7 @@ function make_output_structure(docs::Vector, prettyurls)
131
164
132
165
gitpath = joinpath (outpath, " .git" )
133
166
if isdir (gitpath)
134
- rm (gitpath, recursive= true )
167
+ rm (gitpath, recursive = true )
135
168
end
136
169
end
137
170
@@ -148,7 +181,14 @@ function make_output_structure(docs::Vector, prettyurls)
148
181
return dir
149
182
end
150
183
151
- function make_global_nav (dir, docs, thispagepath, brand_image, search_engine, prettyurls)
184
+ function make_global_nav (
185
+ dir,
186
+ docs:: Vector ,
187
+ thispagepath,
188
+ brand_image,
189
+ search_engine,
190
+ prettyurls,
191
+ )
152
192
nav = Gumbo. HTMLElement {:nav} ([], Gumbo. NullNode (), Dict (" id" => " multi-page-nav" ))
153
193
154
194
if brand_image != = nothing
@@ -180,19 +220,51 @@ function make_global_nav(dir, docs, thispagepath, brand_image, search_engine, pr
180
220
push! (nav. children, navitems)
181
221
182
222
for doc in docs
183
- rp = relpath (joinpath (dir, doc. path), thispagepath)
184
- a = Gumbo. HTMLElement {:a} (
185
- [],
186
- navitems,
187
- Dict (
188
- " href" => string (rp, prettyurls ? " /" : " /index.html" ),
189
- " class" =>
190
- startswith (thispagepath, joinpath (dir, doc. path, " " )) ? # need to force a trailing pathsep here
191
- " nav-link active nav-item" : " nav-link nav-item" ,
192
- ),
193
- )
194
- push! (a. children, Gumbo. HTMLText (a, doc. name))
195
- push! (navitems. children, a)
223
+ 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)
237
+ else # doc isa DropdownNav
238
+ div = Gumbo. HTMLElement {:div} (
239
+ [],
240
+ navitems,
241
+ Dict (" class" => " nav-dropdown" ),
242
+ )
243
+ span = Gumbo. HTMLElement {:span} ([], div, Dict (" class" => " nav-item dropdown-label" ))
244
+ push! (div. children, span)
245
+ push! (span. children, Gumbo. HTMLText (div, doc. name))
246
+ ul = Gumbo. HTMLElement {:ul} ([], div, Dict (" class" => " nav-dropdown-container" ))
247
+ push! (div. children, ul)
248
+ push! (navitems. children, div)
249
+
250
+ for doc in doc. children
251
+ rp = relpath (joinpath (dir, doc. path), thispagepath)
252
+ 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)
265
+ push! (ul. children, li)
266
+ end
267
+ end
196
268
end
197
269
if search_engine != false
198
270
search_engine. engine. inject_html! (navitems)
@@ -249,12 +321,12 @@ end
249
321
250
322
function inject_styles_and_global_navigation (
251
323
dir,
252
- docs:: Vector{MultiDocRef} ,
324
+ docs:: Vector ,
253
325
brand_image,
254
326
custom_stylesheets,
255
327
custom_scripts,
256
328
search_engine,
257
- prettyurls
329
+ prettyurls,
258
330
)
259
331
260
332
if search_engine != false
@@ -283,7 +355,10 @@ function inject_styles_and_global_navigation(
283
355
284
356
285
357
page = read (path, String)
286
- if startswith (page, " <!--This file is automatically generated by Documenter.jl-->" )
358
+ if startswith (
359
+ page,
360
+ " <!--This file is automatically generated by Documenter.jl-->" ,
361
+ )
287
362
continue
288
363
end
289
364
doc = Gumbo. parsehtml (page)
@@ -307,12 +382,18 @@ function inject_styles_and_global_navigation(
307
382
documenter_div = first (el. children)
308
383
if documenter_div isa Gumbo. HTMLElement &&
309
384
Gumbo. getattr (documenter_div, " id" , " " ) == " documenter"
310
- @debug " Could not detect Documenter page layout in $path . This may be due to an old version of Documenter."
385
+ @debug " Could not detect Documenter page layout in $path . This may be due to an old version of Documenter."
311
386
end
312
387
# inject global navigation as first element in body
313
388
314
- global_nav =
315
- make_global_nav (dir, docs, root, brand_image, search_engine, prettyurls)
389
+ global_nav = make_global_nav (
390
+ dir,
391
+ docs,
392
+ root,
393
+ brand_image,
394
+ search_engine,
395
+ prettyurls,
396
+ )
316
397
global_nav. parent = el
317
398
pushfirst! (el. children, global_nav)
318
399
injected += 1
0 commit comments