From 5b1072a2a2fb2e4be0e86329d17c27872d776b10 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 20 Feb 2025 10:48:57 -0500 Subject: [PATCH 01/14] Create an interface for column components other than MultiDocRef --- src/MultiDocumenter.jl | 43 +++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/MultiDocumenter.jl b/src/MultiDocumenter.jl index 34efef2a..ff916aec 100644 --- a/src/MultiDocumenter.jl +++ b/src/MultiDocumenter.jl @@ -25,6 +25,23 @@ Base.@kwdef mutable struct SearchConfig lowfi = false end +""" + abstract type DropdownComponent + +The supertype for any component that can be put in a dropdown column and +rendered using `MultiDocumenter.render(::YourComponent, thispagepath, dir, prettyurls)`. + +All `DropdownComponent`s go in [`Column`](@ref)s, which go in [`MegaDropdownNav`](@ref). + +Any subtype of `DropdownComponent` must implement that `render` method. + +The main subtype is [`MultiDocRef`](@ref), which refers to external documentation +and adds it to the search index. However, there are others like [`ExternalLink`](@ref) +which is used to link to external sites without making them searchable, and +users can implement their own custom components. +""" +abstract type DropdownComponent end + """ struct MultiDocRef @@ -44,7 +61,7 @@ Represents one set of docs that will get an entry in the MultiDocumenter navigat * `fix_canonical_url`: this can be set to `false` to disable the canonical URL fixing for this `MultiDocRef` (see also `canonical_domain` for [`make`](@ref)). """ -struct MultiDocRef +struct MultiDocRef <: DropdownComponent upstream::String path::String name::Any @@ -66,12 +83,12 @@ end struct DropdownNav name::String - children::Vector{MultiDocRef} + children::Vector{DropdownComponent} end struct Column name::Any - children::Vector{MultiDocRef} + children::Vector{DropdownComponent} end struct MegaDropdownNav @@ -84,8 +101,8 @@ struct BrandImage imagepath::String end -function walk_outputs(f, root, docs::Vector{MultiDocRef}, dirs::Vector{String}) - for ref in docs +function walk_outputs(f, root, docs::Vector, dirs::Vector{String}) + for ref in filter(x -> x isa MultiDocRef, docs) p = joinpath(root, ref.path) for dir in dirs dirpath = joinpath(p, dir) @@ -143,7 +160,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir` """ function make( outdir, - docs::Vector; + docs::Vector{DropdownComponent}; assets_dir = nothing, brand_image::Union{Nothing,BrandImage} = nothing, custom_stylesheets = [], @@ -256,9 +273,9 @@ function make( end function flatten_multidocrefs(docs::Vector) - out = MultiDocRef[] + out = [] for doc in docs - if doc isa MultiDocRef + if doc isa DropdownComponent push!(out, doc) elseif doc isa MegaDropdownNav for col in doc.columns @@ -275,8 +292,8 @@ function flatten_multidocrefs(docs::Vector) out end -function maybe_clone(docs::Vector{MultiDocRef}) - for doc in docs +function maybe_clone(docs::Vector{<: DropdownComponent}) + for doc in filter(x -> x isa MultiDocRef, docs) if !isdir(doc.upstream) if isempty(doc.giturl) error( @@ -314,14 +331,14 @@ function maybe_clone(docs::Vector{MultiDocRef}) end function make_output_structure( - docs::Vector{MultiDocRef}, + docs::Vector{<: DropdownComponent}, prettyurls, hide_previews; canonical::Union{AbstractString,Nothing}, ) dir = mktempdir() - for doc in docs + for doc in Iterators.filter(x -> x isa MultiDocRef, docs) outpath = joinpath(dir, doc.path) mkpath(dirname(outpath)) @@ -355,7 +372,7 @@ end function make_global_nav( dir, - docs::Vector, + docs::Vector{<: DropdownComponent}, thispagepath, brand_image, search_engine, From 7acd3aef67ff94f222004cc09f1e98993a20d9d1 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 20 Feb 2025 10:57:26 -0500 Subject: [PATCH 02/14] Fix whitespace issues suggested by Semgrep Co-authored-by: semgrep-code-juliacomputing-new[bot] <177960334+semgrep-code-juliacomputing-new[bot]@users.noreply.github.com> --- src/MultiDocumenter.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MultiDocumenter.jl b/src/MultiDocumenter.jl index ff916aec..3e7302d5 100644 --- a/src/MultiDocumenter.jl +++ b/src/MultiDocumenter.jl @@ -35,9 +35,9 @@ All `DropdownComponent`s go in [`Column`](@ref)s, which go in [`MegaDropdownNav` Any subtype of `DropdownComponent` must implement that `render` method. -The main subtype is [`MultiDocRef`](@ref), which refers to external documentation -and adds it to the search index. However, there are others like [`ExternalLink`](@ref) -which is used to link to external sites without making them searchable, and +The main subtype is [`MultiDocRef`](@ref), which refers to external documentation +and adds it to the search index. However, there are others like [`ExternalLink`](@ref) +which is used to link to external sites without making them searchable, and users can implement their own custom components. """ abstract type DropdownComponent end From 4aeb4be6441dc8f109972c08cb75f0d0f8fae6bb Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 20 Feb 2025 11:20:34 -0500 Subject: [PATCH 03/14] Don't restrict types --- src/MultiDocumenter.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MultiDocumenter.jl b/src/MultiDocumenter.jl index 3e7302d5..e341b24b 100644 --- a/src/MultiDocumenter.jl +++ b/src/MultiDocumenter.jl @@ -160,7 +160,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir` """ function make( outdir, - docs::Vector{DropdownComponent}; + docs::Vector; assets_dir = nothing, brand_image::Union{Nothing,BrandImage} = nothing, custom_stylesheets = [], @@ -292,7 +292,7 @@ function flatten_multidocrefs(docs::Vector) out end -function maybe_clone(docs::Vector{<: DropdownComponent}) +function maybe_clone(docs::Vector) for doc in filter(x -> x isa MultiDocRef, docs) if !isdir(doc.upstream) if isempty(doc.giturl) @@ -331,7 +331,7 @@ function maybe_clone(docs::Vector{<: DropdownComponent}) end function make_output_structure( - docs::Vector{<: DropdownComponent}, + docs::Vector, prettyurls, hide_previews; canonical::Union{AbstractString,Nothing}, @@ -372,7 +372,7 @@ end function make_global_nav( dir, - docs::Vector{<: DropdownComponent}, + docs::Vector, thispagepath, brand_image, search_engine, From 4d4fab3ad650a615db949169a9c9100e14328eda Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 20 Feb 2025 11:37:15 -0500 Subject: [PATCH 04/14] add a Link component to emphasize the renderer interface --- src/MultiDocumenter.jl | 8 ++++++++ src/renderers.jl | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/MultiDocumenter.jl b/src/MultiDocumenter.jl index e341b24b..f2e30612 100644 --- a/src/MultiDocumenter.jl +++ b/src/MultiDocumenter.jl @@ -81,6 +81,14 @@ function MultiDocRef(; MultiDocRef(upstream, path, name, fix_canonical_url, giturl, branch) end + +struct Link <: MultiDocumenter.DropdownComponent + text::String + link::String +end + +Link(link::String) = Link(link, link) + struct DropdownNav name::String children::Vector{DropdownComponent} diff --git a/src/renderers.jl b/src/renderers.jl index 76d6cedf..876e34b7 100644 --- a/src/renderers.jl +++ b/src/renderers.jl @@ -36,6 +36,12 @@ function render(doc::MultiDocRef, dir, thispagepath, prettyurls) """ end +function render(c::Link, doc, thispage, prettyurls) + return @htl """ + $(c.text) + """ # TODO: add "external link" icon after, either chain or arrow exiting box. +end + function render(doc::DropdownNav, dir, thispagepath, prettyurls) return @htl """