@@ -26,7 +26,25 @@ Base.@kwdef mutable struct SearchConfig
26
26
end
27
27
28
28
"""
29
- struct MultiDocRef
29
+ abstract type DropdownComponent
30
+
31
+ The supertype for any component that can be put in a dropdown column and
32
+ rendered using `MultiDocumenter.render(::YourComponent, thispagepath, dir, prettyurls)`.
33
+
34
+ All `DropdownComponent`s go in [`Column`](@ref)s, which go in [`MegaDropdownNav`](@ref).
35
+
36
+ Any subtype of `DropdownComponent` must implement that `render` method.
37
+
38
+ The main subtype is [`MultiDocRef`](@ref), which refers to external documentation
39
+ and adds it to the search index. However, there are others like [`Link`](@ref)
40
+ which is used to link to external sites without making them searchable, and
41
+ users can implement their own custom components.
42
+ """
43
+ abstract type DropdownComponent end
44
+
45
+ """
46
+ struct MultiDocRef <: DropdownComponent
47
+ MultiDocRef(; upstream, name, path, giturl = "", branch = "gh-pages", fix_canonical_url = true)
30
48
31
49
Represents one set of docs that will get an entry in the MultiDocumenter navigation.
32
50
@@ -44,7 +62,7 @@ Represents one set of docs that will get an entry in the MultiDocumenter navigat
44
62
* `fix_canonical_url`: this can be set to `false` to disable the canonical URL fixing
45
63
for this `MultiDocRef` (see also `canonical_domain` for [`make`](@ref)).
46
64
"""
47
- struct MultiDocRef
65
+ struct MultiDocRef <: DropdownComponent
48
66
upstream:: String
49
67
path:: String
50
68
name:: Any
@@ -64,14 +82,28 @@ function MultiDocRef(;
64
82
MultiDocRef (upstream, path, name, fix_canonical_url, giturl, branch)
65
83
end
66
84
85
+ """
86
+ Link([text::String], link::String, [isexternal::Bool]) <: DropdownComponent
87
+
88
+ Represents a link to an external site.
89
+ """
90
+ struct Link <: MultiDocumenter.DropdownComponent
91
+ text:: String
92
+ link:: String
93
+ isexternal:: Bool
94
+ end
95
+
96
+ Link (link:: String ) = Link (link, link)
97
+ Link (text:: String , link:: String ) = Link (text, link, contains (link, " //" ))
98
+
67
99
struct DropdownNav
68
100
name:: String
69
- children:: Vector{MultiDocRef }
101
+ children:: Vector{DropdownComponent }
70
102
end
71
103
72
104
struct Column
73
105
name:: Any
74
- children:: Vector{MultiDocRef }
106
+ children:: Vector{DropdownComponent }
75
107
end
76
108
77
109
struct MegaDropdownNav
@@ -84,8 +116,8 @@ struct BrandImage
84
116
imagepath:: String
85
117
end
86
118
87
- function walk_outputs (f, root, docs:: Vector{MultiDocRef} , dirs:: Vector{String} )
88
- for ref in docs
119
+ function walk_outputs (f, root, docs:: Vector , dirs:: Vector{String} )
120
+ for ref in filter (x -> x isa MultiDocRef, docs)
89
121
p = joinpath (root, ref. path)
90
122
for dir in dirs
91
123
dirpath = joinpath (p, dir)
@@ -199,10 +231,10 @@ function make(
199
231
end
200
232
site_root_url = string (canonical_domain, rstrip (rootpath, ' /' ))
201
233
202
- maybe_clone (flatten_multidocrefs (docs))
234
+ maybe_clone (flatten_dropdowncomponents (docs))
203
235
204
236
dir = make_output_structure (
205
- flatten_multidocrefs (docs),
237
+ flatten_dropdowncomponents (docs),
206
238
prettyurls,
207
239
hide_previews;
208
240
canonical = site_root_url,
@@ -235,7 +267,7 @@ function make(
235
267
if search_engine != false
236
268
search_engine. engine. build_search_index (
237
269
dir,
238
- flatten_multidocrefs (docs),
270
+ flatten_dropdowncomponents (docs),
239
271
search_engine,
240
272
rootpath,
241
273
)
@@ -255,10 +287,10 @@ function make(
255
287
return outdir
256
288
end
257
289
258
- function flatten_multidocrefs (docs:: Vector )
259
- out = MultiDocRef []
290
+ function flatten_dropdowncomponents (docs:: Vector )
291
+ out = DropdownComponent []
260
292
for doc in docs
261
- if doc isa MultiDocRef
293
+ if doc isa DropdownComponent
262
294
push! (out, doc)
263
295
elseif doc isa MegaDropdownNav
264
296
for col in doc. columns
@@ -272,11 +304,11 @@ function flatten_multidocrefs(docs::Vector)
272
304
end
273
305
end
274
306
end
275
- out
307
+ return out
276
308
end
277
309
278
- function maybe_clone (docs:: Vector{MultiDocRef} )
279
- for doc in docs
310
+ function maybe_clone (docs:: Vector )
311
+ for doc in filter (x -> x isa MultiDocRef, docs)
280
312
if ! isdir (doc. upstream)
281
313
if isempty (doc. giturl)
282
314
error (
@@ -311,17 +343,18 @@ function maybe_clone(docs::Vector{MultiDocRef})
311
343
end
312
344
end
313
345
end
346
+ return nothing
314
347
end
315
348
316
349
function make_output_structure (
317
- docs:: Vector{MultiDocRef } ,
350
+ docs:: Vector{DropdownComponent } ,
318
351
prettyurls,
319
352
hide_previews;
320
353
canonical:: Union{AbstractString,Nothing} ,
321
354
)
322
355
dir = mktempdir ()
323
356
324
- for doc in docs
357
+ for doc in Iterators . filter (x -> x isa MultiDocRef, docs)
325
358
outpath = joinpath (dir, doc. path)
326
359
327
360
mkpath (dirname (outpath))
0 commit comments