From 1ad3200b50c4ff12390db8c00c5b42328ce3c8e7 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Fri, 12 Aug 2022 16:08:14 +0200 Subject: [PATCH] Add prettyurls option --- src/MultiDocumenter.jl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/MultiDocumenter.jl b/src/MultiDocumenter.jl index 080c1b3b..42a144e9 100644 --- a/src/MultiDocumenter.jl +++ b/src/MultiDocumenter.jl @@ -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`. @@ -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, @@ -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) @@ -75,6 +78,7 @@ function make( custom_stylesheets, custom_scripts, search_engine, + prettyurls ) if search_engine != false @@ -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 @@ -105,7 +109,7 @@ function make_output_structure(docs::Vector) io, """ - + """, ) end @@ -113,7 +117,7 @@ function make_output_structure(docs::Vector) 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 @@ -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", @@ -215,6 +219,7 @@ function inject_styles_and_global_navigation( custom_stylesheets, custom_scripts, search_engine, + prettyurls ) if search_engine != false @@ -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