Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prettyurls option #9

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Changes from all 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
19 changes: 12 additions & 7 deletions src/MultiDocumenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ end
brand_image,
custom_stylesheets = [],
custom_scripts = [],
search_engine = SearchConfig()
search_engine = SearchConfig(),
prettyurls = true
)

Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`.
Expand All @@ -49,6 +50,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
- `custom_stylesheets` is a `Vector{String}` of stylesheets injected into each page.
- `custom_scripts` is a `Vector{String}` of scripts injected into each page.
- `search_engine` inserts a global search bar. See [`SearchConfig`](@ref) for more details.
- `prettyurls` removes all `index.html` suffixes from links in the global navigation.
"""
function make(
outdir,
Expand All @@ -58,9 +60,10 @@ function make(
custom_stylesheets = [],
custom_scripts = [],
search_engine = SearchConfig(index_versions = ["stable"], engine = FlexSearch),
prettyurls = true
)

dir = make_output_structure(docs)
dir = make_output_structure(docs, prettyurls)
out_assets = joinpath(dir, "assets")
if assets_dir !== nothing && isdir(assets_dir)
cp(assets_dir, out_assets)
Expand All @@ -75,6 +78,7 @@ function make(
custom_stylesheets,
custom_scripts,
search_engine,
prettyurls
)

if search_engine != false
Expand All @@ -87,7 +91,7 @@ function make(
return outdir
end

function make_output_structure(docs::Vector)
function make_output_structure(docs::Vector, prettyurls)
dir = mktempdir()

for doc in docs
Expand All @@ -105,15 +109,15 @@ function make_output_structure(docs::Vector)
io,
"""
<!--This file is automatically generated by MultiDocumenter.jl-->
<meta http-equiv="refresh" content="0; url=./$(first(docs).path)/index.html"/>
<meta http-equiv="refresh" content="0; url=./$(string(first(docs).path), prettyurls ? "/" : "/index.html")"/>
""",
)
end

return dir
end

function make_global_nav(dir, docs, thispagepath, brand_image, search_engine)
function make_global_nav(dir, docs, thispagepath, brand_image, search_engine, prettyurls)
nav = Gumbo.HTMLElement{:nav}([], Gumbo.NullNode(), Dict("id" => "multi-page-nav"))

if brand_image !== nothing
Expand Down Expand Up @@ -147,7 +151,7 @@ function make_global_nav(dir, docs, thispagepath, brand_image, search_engine)
[],
navitems,
Dict(
"href" => string(rp, "/", "index.html"),
"href" => string(rp, prettyurls ? "/" : "/index.html"),
"class" =>
startswith(thispagepath, joinpath(dir, doc.path)) ?
"nav-link active nav-item" : "nav-link nav-item",
Expand Down Expand Up @@ -215,6 +219,7 @@ function inject_styles_and_global_navigation(
custom_stylesheets,
custom_scripts,
search_engine,
prettyurls
)

if search_engine != false
Expand Down Expand Up @@ -268,7 +273,7 @@ function inject_styles_and_global_navigation(
# inject global navigation as first element in body

global_nav =
make_global_nav(dir, docs, root, brand_image, search_engine)
make_global_nav(dir, docs, root, brand_image, search_engine, prettyurls)
global_nav.parent = el
pushfirst!(el.children, global_nav)
injected += 1
Expand Down