Skip to content

Commit 0db0888

Browse files
authored
Merge pull request #9 from JuliaComputing/sp/prettyurls
Add prettyurls option
2 parents add7c36 + 1ad3200 commit 0db0888

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/MultiDocumenter.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ end
3838
brand_image,
3939
custom_stylesheets = [],
4040
custom_scripts = [],
41-
search_engine = SearchConfig()
41+
search_engine = SearchConfig(),
42+
prettyurls = true
4243
)
4344
4445
Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`.
@@ -49,6 +50,7 @@ Aggregates multiple Documenter.jl-based documentation pages `docs` into `outdir`
4950
- `custom_stylesheets` is a `Vector{String}` of stylesheets injected into each page.
5051
- `custom_scripts` is a `Vector{String}` of scripts injected into each page.
5152
- `search_engine` inserts a global search bar. See [`SearchConfig`](@ref) for more details.
53+
- `prettyurls` removes all `index.html` suffixes from links in the global navigation.
5254
"""
5355
function make(
5456
outdir,
@@ -58,9 +60,10 @@ function make(
5860
custom_stylesheets = [],
5961
custom_scripts = [],
6062
search_engine = SearchConfig(index_versions = ["stable"], engine = FlexSearch),
63+
prettyurls = true
6164
)
6265

63-
dir = make_output_structure(docs)
66+
dir = make_output_structure(docs, prettyurls)
6467
out_assets = joinpath(dir, "assets")
6568
if assets_dir !== nothing && isdir(assets_dir)
6669
cp(assets_dir, out_assets)
@@ -75,6 +78,7 @@ function make(
7578
custom_stylesheets,
7679
custom_scripts,
7780
search_engine,
81+
prettyurls
7882
)
7983

8084
if search_engine != false
@@ -87,7 +91,7 @@ function make(
8791
return outdir
8892
end
8993

90-
function make_output_structure(docs::Vector)
94+
function make_output_structure(docs::Vector, prettyurls)
9195
dir = mktempdir()
9296

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

113117
return dir
114118
end
115119

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

119123
if brand_image !== nothing
@@ -147,7 +151,7 @@ function make_global_nav(dir, docs, thispagepath, brand_image, search_engine)
147151
[],
148152
navitems,
149153
Dict(
150-
"href" => string(rp, "/", "index.html"),
154+
"href" => string(rp, prettyurls ? "/" : "/index.html"),
151155
"class" =>
152156
startswith(thispagepath, joinpath(dir, doc.path)) ?
153157
"nav-link active nav-item" : "nav-link nav-item",
@@ -215,6 +219,7 @@ function inject_styles_and_global_navigation(
215219
custom_stylesheets,
216220
custom_scripts,
217221
search_engine,
222+
prettyurls
218223
)
219224

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

270275
global_nav =
271-
make_global_nav(dir, docs, root, brand_image, search_engine)
276+
make_global_nav(dir, docs, root, brand_image, search_engine, prettyurls)
272277
global_nav.parent = el
273278
pushfirst!(el.children, global_nav)
274279
injected += 1

0 commit comments

Comments
 (0)