Skip to content

Commit

Permalink
Merge pull request #9 from JuliaComputing/sp/prettyurls
Browse files Browse the repository at this point in the history
Add prettyurls option
  • Loading branch information
pfitzseb authored Aug 12, 2022
2 parents add7c36 + 1ad3200 commit 0db0888
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 0db0888

Please sign in to comment.