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 version selector dropdown menu #358

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions assets/html/documenter.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ nav.toc input {
font-size: smaller;
}

nav.toc select {
display: block;
height: 2em;
width: calc(100% - 3em);
margin: 5px auto;
font-size: smaller;
text-align: center;
}

nav.toc > ul * {
margin: 0;
}
Expand Down
7 changes: 7 additions & 0 deletions assets/html/documenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ require(['mathjax'], function(MathJax) {

require(['jquery', 'highlight', 'highlight-julia'], function($, hljs) {
$(document).ready(function() {
if (typeof DOC_VERSIONS !== 'undefined') {
var version_selector = $("#version-selector");
DOC_VERSIONS.forEach(function(each) {
var option = $("<option value='" + documenterBaseURL + "/../" + each + "'>" + each + "</option>");
version_selector.append(option);
});
}
hljs.initHighlighting();
})

Expand Down
4 changes: 4 additions & 0 deletions src/Documenter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ function deploydocs(;
end
end

# Create the versions.js file containing a list of all docs
# versions. This must always happen after the folder copying.
Writers.HTMLWriter.generate_version_file(pwd())

# Add, commit, and push the docs to the remote.
run(`git add -A .`)
try run(`git commit -m "build based on $sha"`) end
Expand Down
40 changes: 36 additions & 4 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ function render_head(ctx, navnode, additional_scripts)
Symbol("data-main") => relhref(src, ctx.documenter_js)
],

script[:src => relhref(src, "../versions.js")],

# Additional JS files needed for the search page.
[script[:src => relhref(src, each)] for each in additional_scripts],

Expand Down Expand Up @@ -248,12 +250,12 @@ end
# ------------------------------------------------------------------------------

function render_navmenu(ctx, navnode)
@tags a form h1 img input nav
@tags a form h1 img input nav div select option
src = get(navnode.page)
navmenu = nav[".toc"]
if !isempty(ctx.logo)
push!(navmenu.nodes,
a[:href => ""]( # TODO: link to github?
a[:href => relhref(src, "index.html")](
img[
".logo",
:src => relhref(src, ctx.logo),
Expand All @@ -265,12 +267,22 @@ function render_navmenu(ctx, navnode)
push!(navmenu.nodes, h1(ctx.doc.user.sitename))
push!(navmenu.nodes,
form[".search", :action => relhref(src, "search.html")](
select[
"#version-selector",
:onChange => "window.location.href=this.value",
](
option[
:value => "#",
:selected => "selected",
:disabled => "disabled",
]("Version"),
),
input[
"#search-query",
:name => "q",
:type => "text",
:placeholder => "Search docs"
]
:placeholder => "Search docs",
],
)
)
push!(navmenu.nodes, navitem(ctx, navnode))
Expand Down Expand Up @@ -365,6 +377,26 @@ function render_article(ctx, navnode)
article["#docs"](art_header, pagenodes, art_footer)
end

function generate_version_file(dir::AbstractString)
local named_folders = []
local release_folders = []
local tag_folders = []
for each in readdir(dir)
each in ("stable", "latest") ? push!(named_folders, each) :
ismatch(r"release\-\d+\.\d+", each) ? push!(release_folders, each) :
ismatch(Base.VERSION_REGEX, each) ? push!(tag_folders, each) : nothing
end
open(joinpath(dir, "versions.js"), "w") do buf
println(buf, "var DOC_VERSIONS = [")
for group in (named_folders, release_folders, tag_folders)
for folder in sort!(group, rev = true)
println(buf, " \"", folder, "\",")
end
end
println(buf, "];")
end
end

## domify(...)
# ------------

Expand Down