Skip to content

Commit fc8496d

Browse files
committed
DOCS: Add version chooser to theme
This requires tweaking the theme to add some elements, plus a version of our previous javascript to populate it based on json in the root of the docs repo.
1 parent 2e3f520 commit fc8496d

File tree

5 files changed

+112
-18
lines changed

5 files changed

+112
-18
lines changed

docs/_static/doc_shared.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const proj = "MetPy";
2+
3+
$(document).ready(function() {
4+
cur_ver = DOCUMENTATION_OPTIONS.VERSION;
5+
end = cur_ver.lastIndexOf('.');
6+
if (end > -1) {
7+
cur_ver = 'v' + cur_ver.substring(0, end);
8+
}
9+
console.log('cur_ver: ' + cur_ver);
10+
11+
$.getJSON('/' + proj + '/versions.json', function(data) {
12+
if (cur_ver !== data.latest) {
13+
let msg;
14+
if (cur_ver.includes('dev') || data.prereleases.indexOf(cur_ver) > -1) {
15+
msg = 'development / pre-release';
16+
} else {
17+
msg = 'previous';
18+
}
19+
content = $('<div class="version-alert">This documentation page is for a ' + msg +
20+
' version. For the latest release version, go to <a href="https://unidata.github.io/MetPy/latest/">https://unidata.github.io/MetPy/latest/</a>');
21+
$('#banner').append(content);
22+
}
23+
24+
$.each(data.versions, function() {
25+
if (this !== 'latest') {
26+
const url = DOCUMENTATION_OPTIONS.URL_ROOT + '../' + this;
27+
const name = this.startsWith('v') ? this.substring(1) : this;
28+
$('#version-menu').append('<a class="dropdown-item" href="' + url + '">' + name + '</a>');
29+
}
30+
});
31+
});
32+
});
33+
34+
// Borrowed from Bokeh docs to look for an alert.html at the base of the
35+
// docs repo and add that to the banner if present.
36+
$(document).ready(function () {
37+
$.get('/' + proj + '/alert.html', function (data) {
38+
if (data.length > 0) {
39+
content = $('<div class="news-alert">' + data + '</div>')
40+
$('#banner').prepend(content);
41+
}
42+
})
43+
})

docs/_static/pop_ver.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

docs/_templates/docs-navbar.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<div class="container-xl">
2+
3+
<a class="navbar-brand" href="{{ pathto(master_doc) }}">
4+
{% if logo %}
5+
<img src="{{ pathto('_static/' + logo, 1) }}" class="logo" alt="logo" />
6+
{% else %}
7+
<p class="title">{{ project }}</p>
8+
{% endif %}
9+
</a>
10+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false" aria-label="Toggle navigation">
11+
<span class="navbar-toggler-icon"></span>
12+
</button>
13+
14+
{# Removed col-lg-10 to match align:left from next version #}
15+
<div id="navbar-menu" class="collapse navbar-collapse">
16+
<ul id="navbar-main-elements" class="navbar-nav mr-auto">
17+
18+
{# Begin adding version chooser #}
19+
<li class="nav-item dropdown">
20+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
21+
Version {{ version }}
22+
</a>
23+
<div class="dropdown-menu" aria-labelledby="navbarDropdown" id="version-menu"></div>
24+
</li>
25+
{# End #}
26+
27+
{% set nav = get_nav_object(maxdepth=1, collapse=True) %}
28+
{% for main_nav_item in nav %}
29+
<li class="nav-item {% if main_nav_item.active%}active{% endif %}">
30+
<a class="nav-link" href="{{ main_nav_item.url }}">{{ main_nav_item.title }}</a>
31+
</li>
32+
{% endfor %}
33+
{% for external_link in theme_external_links %}
34+
<li class="nav-item">
35+
<a class="nav-link nav-external" href="{{ external_link.url }}">{{ external_link.name }}<i class="fas fa-external-link-alt"></i></a>
36+
</li>
37+
{% endfor %}
38+
</ul>
39+
40+
41+
{% if theme_search_bar_position == 'navbar' %}
42+
{%- include "search-field.html" %}
43+
{% endif %}
44+
45+
<ul class="navbar-nav">
46+
{% if theme_github_url | length > 2 %}
47+
<li class="nav-item">
48+
<a class="nav-link" href="{{ theme_github_url }}" target="_blank" rel="noopener">
49+
<span><i class="fab fa-github-square"></i></span>
50+
</a>
51+
</li>
52+
{% endif %}
53+
{% if theme_twitter_url | length > 2 %}
54+
<li class="nav-item">
55+
<a class="nav-link" href="{{ theme_twitter_url }}" target="_blank" rel="noopener">
56+
<span><i class="fab fa-twitter-square"></i></span>
57+
</a>
58+
</li>
59+
{% endif %}
60+
</ul>
61+
</div>
62+
</div>

docs/_templates/layout.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{% extends "!layout.html" %}
2+
{% block docs_navbar %}
3+
{{ super() }}
4+
{# Added to support a banner with an alert #}
5+
<div class="container-fluid" id="banner"></div>
6+
{% endblock %}

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
html_static_path = ['_static']
221221

222222
html_css_files = ['theme-unidata.css']
223-
html_js_files = ['pop_ver.js']
223+
html_js_files = ['doc_shared.js']
224224

225225
# Add any extra paths that contain custom files (such as robots.txt or
226226
# .htaccess) here, relative to this directory. These files are copied

0 commit comments

Comments
 (0)