Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ docs = [
name = "JuliaInterpreter",
giturl = "https://github.com/JuliaDebug/JuliaInterpreter.jl.git",
),
MultiDocumenter.Link(
"Lux",
"https://github.com/avik-pal/Lux.jl",
),
],
),
MultiDocumenter.Column(
Expand Down
47 changes: 36 additions & 11 deletions src/MultiDocumenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -64,14 +81,22 @@ 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{MultiDocRef}
children::Vector{DropdownComponent}
end

struct Column
name::Any
children::Vector{MultiDocRef}
children::Vector{DropdownComponent}
end

struct MegaDropdownNav
Expand All @@ -84,8 +109,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)
Expand Down Expand Up @@ -256,9 +281,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
Expand All @@ -275,8 +300,8 @@ function flatten_multidocrefs(docs::Vector)
out
end

function maybe_clone(docs::Vector{MultiDocRef})
for doc in docs
function maybe_clone(docs::Vector)
for doc in filter(x -> x isa MultiDocRef, docs)
if !isdir(doc.upstream)
if isempty(doc.giturl)
error(
Expand Down Expand Up @@ -314,14 +339,14 @@ function maybe_clone(docs::Vector{MultiDocRef})
end

function make_output_structure(
docs::Vector{MultiDocRef},
docs::Vector,
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))
Expand Down
6 changes: 6 additions & 0 deletions src/renderers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function render(doc::MultiDocRef, dir, thispagepath, prettyurls)
"""
end

function render(c::Link, doc, thispage, prettyurls)
return @htl """
<a href=$(c.link) class="nav-link nav-item">$(c.text)</a>
""" # TODO: add "external link" icon after, either chain or arrow exiting box.
end

function render(doc::DropdownNav, dir, thispagepath, prettyurls)
return @htl """
<div class="nav-dropdown">
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ docs = [
name = "Lux",
giturl = "https://github.com/avik-pal/Lux.jl",
),
MultiDocumenter.Link(
"JuliaHub",
"https://juliahub.com",
),
],
),
MultiDocumenter.Column(
Expand Down
Loading