@@ -26,7 +26,25 @@ Base.@kwdef mutable struct SearchConfig
2626end
2727
2828"""
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)
3048
3149Represents one set of docs that will get an entry in the MultiDocumenter navigation.
3250
@@ -44,7 +62,7 @@ Represents one set of docs that will get an entry in the MultiDocumenter navigat
4462* `fix_canonical_url`: this can be set to `false` to disable the canonical URL fixing
4563 for this `MultiDocRef` (see also `canonical_domain` for [`make`](@ref)).
4664"""
47- struct MultiDocRef
65+ struct MultiDocRef <: DropdownComponent
4866 upstream:: String
4967 path:: String
5068 name:: Any
@@ -64,14 +82,28 @@ function MultiDocRef(;
6482 MultiDocRef (upstream, path, name, fix_canonical_url, giturl, branch)
6583end
6684
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+
6799struct DropdownNav
68100 name:: String
69- children:: Vector{MultiDocRef }
101+ children:: Vector{DropdownComponent }
70102end
71103
72104struct Column
73105 name:: Any
74- children:: Vector{MultiDocRef }
106+ children:: Vector{DropdownComponent }
75107end
76108
77109struct MegaDropdownNav
@@ -84,8 +116,8 @@ struct BrandImage
84116 imagepath:: String
85117end
86118
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)
89121 p = joinpath (root, ref. path)
90122 for dir in dirs
91123 dirpath = joinpath (p, dir)
@@ -199,10 +231,10 @@ function make(
199231 end
200232 site_root_url = string (canonical_domain, rstrip (rootpath, ' /' ))
201233
202- maybe_clone (flatten_multidocrefs (docs))
234+ maybe_clone (flatten_dropdowncomponents (docs))
203235
204236 dir = make_output_structure (
205- flatten_multidocrefs (docs),
237+ flatten_dropdowncomponents (docs),
206238 prettyurls,
207239 hide_previews;
208240 canonical = site_root_url,
@@ -235,7 +267,7 @@ function make(
235267 if search_engine != false
236268 search_engine. engine. build_search_index (
237269 dir,
238- flatten_multidocrefs (docs),
270+ flatten_dropdowncomponents (docs),
239271 search_engine,
240272 rootpath,
241273 )
@@ -255,10 +287,10 @@ function make(
255287 return outdir
256288end
257289
258- function flatten_multidocrefs (docs:: Vector )
259- out = MultiDocRef []
290+ function flatten_dropdowncomponents (docs:: Vector )
291+ out = DropdownComponent []
260292 for doc in docs
261- if doc isa MultiDocRef
293+ if doc isa DropdownComponent
262294 push! (out, doc)
263295 elseif doc isa MegaDropdownNav
264296 for col in doc. columns
@@ -272,11 +304,11 @@ function flatten_multidocrefs(docs::Vector)
272304 end
273305 end
274306 end
275- out
307+ return out
276308end
277309
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)
280312 if ! isdir (doc. upstream)
281313 if isempty (doc. giturl)
282314 error (
@@ -311,17 +343,18 @@ function maybe_clone(docs::Vector{MultiDocRef})
311343 end
312344 end
313345 end
346+ return nothing
314347end
315348
316349function make_output_structure (
317- docs:: Vector{MultiDocRef } ,
350+ docs:: Vector{DropdownComponent } ,
318351 prettyurls,
319352 hide_previews;
320353 canonical:: Union{AbstractString,Nothing} ,
321354)
322355 dir = mktempdir ()
323356
324- for doc in docs
357+ for doc in Iterators . filter (x -> x isa MultiDocRef, docs)
325358 outpath = joinpath (dir, doc. path)
326359
327360 mkpath (dirname (outpath))
0 commit comments