Skip to content

Commit 5b1072a

Browse files
committed
Create an interface for column components other than MultiDocRef
1 parent 0caa723 commit 5b1072a

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/MultiDocumenter.jl

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ Base.@kwdef mutable struct SearchConfig
2525
lowfi = false
2626
end
2727

28+
"""
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 [`ExternalLink`](@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+
2845
"""
2946
struct MultiDocRef
3047
@@ -44,7 +61,7 @@ Represents one set of docs that will get an entry in the MultiDocumenter navigat
4461
* `fix_canonical_url`: this can be set to `false` to disable the canonical URL fixing
4562
for this `MultiDocRef` (see also `canonical_domain` for [`make`](@ref)).
4663
"""
47-
struct MultiDocRef
64+
struct MultiDocRef <: DropdownComponent
4865
upstream::String
4966
path::String
5067
name::Any
@@ -66,12 +83,12 @@ end
6683

6784
struct DropdownNav
6885
name::String
69-
children::Vector{MultiDocRef}
86+
children::Vector{DropdownComponent}
7087
end
7188

7289
struct Column
7390
name::Any
74-
children::Vector{MultiDocRef}
91+
children::Vector{DropdownComponent}
7592
end
7693

7794
struct MegaDropdownNav
@@ -84,8 +101,8 @@ struct BrandImage
84101
imagepath::String
85102
end
86103

87-
function walk_outputs(f, root, docs::Vector{MultiDocRef}, dirs::Vector{String})
88-
for ref in docs
104+
function walk_outputs(f, root, docs::Vector, dirs::Vector{String})
105+
for ref in filter(x -> x isa MultiDocRef, docs)
89106
p = joinpath(root, ref.path)
90107
for dir in dirs
91108
dirpath = joinpath(p, dir)
@@ -143,7 +160,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
143160
"""
144161
function make(
145162
outdir,
146-
docs::Vector;
163+
docs::Vector{DropdownComponent};
147164
assets_dir = nothing,
148165
brand_image::Union{Nothing,BrandImage} = nothing,
149166
custom_stylesheets = [],
@@ -256,9 +273,9 @@ function make(
256273
end
257274

258275
function flatten_multidocrefs(docs::Vector)
259-
out = MultiDocRef[]
276+
out = []
260277
for doc in docs
261-
if doc isa MultiDocRef
278+
if doc isa DropdownComponent
262279
push!(out, doc)
263280
elseif doc isa MegaDropdownNav
264281
for col in doc.columns
@@ -275,8 +292,8 @@ function flatten_multidocrefs(docs::Vector)
275292
out
276293
end
277294

278-
function maybe_clone(docs::Vector{MultiDocRef})
279-
for doc in docs
295+
function maybe_clone(docs::Vector{<: DropdownComponent})
296+
for doc in filter(x -> x isa MultiDocRef, docs)
280297
if !isdir(doc.upstream)
281298
if isempty(doc.giturl)
282299
error(
@@ -314,14 +331,14 @@ function maybe_clone(docs::Vector{MultiDocRef})
314331
end
315332

316333
function make_output_structure(
317-
docs::Vector{MultiDocRef},
334+
docs::Vector{<: DropdownComponent},
318335
prettyurls,
319336
hide_previews;
320337
canonical::Union{AbstractString,Nothing},
321338
)
322339
dir = mktempdir()
323340

324-
for doc in docs
341+
for doc in Iterators.filter(x -> x isa MultiDocRef, docs)
325342
outpath = joinpath(dir, doc.path)
326343

327344
mkpath(dirname(outpath))
@@ -355,7 +372,7 @@ end
355372

356373
function make_global_nav(
357374
dir,
358-
docs::Vector,
375+
docs::Vector{<: DropdownComponent},
359376
thispagepath,
360377
brand_image,
361378
search_engine,

0 commit comments

Comments
 (0)