Skip to content

Commit cf7d532

Browse files
committed
ENH: Add javacript to dynamically populate version chooser
This reads a versions.json from the root of the documentation repository to determine what versions are available. Set up this json file to be created during documentation deployment.
1 parent ba77131 commit cf7d532

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

ci/deploy_docs.sh

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ if [[ "${VERSION}" != "dev" ]]; then
3535
ln -snf ${VERSION} latest
3636
fi
3737

38+
# Generate our json list of versions
39+
echo Generating versions.json...
40+
${TRAVIS_BUILD_DIR}/ci/gen_versions_json.py
41+
3842
echo Staging...
3943
git add -A .
4044
if [[ "${VERSION}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then

ci/gen_versions_json.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2017 MetPy Developers.
3+
# Distributed under the terms of the BSD 3-Clause License.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
"""Generate versions.json from directory with different doc versions."""
6+
7+
import glob
8+
9+
with open('versions.json', 'wt') as version_file:
10+
version_strings = ','.join('"{}"'.format(d) for d in glob.glob('v*.[0-9]*'))
11+
version_file.write('{"versions":["latest","dev",' + version_strings + ']}\n')

docs/_static/pop_ver.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
$(document).ready(function() {
2+
var proj_end = document.baseURI.indexOf("MetPy") + 6;
3+
var end = document.baseURI.indexOf("/", proj_end);
4+
var cur_ver = document.baseURI.substring(proj_end, end);
5+
var name = cur_ver.startsWith('v') ? cur_ver.substring(1) : cur_ver;
6+
var mylist = $("#version-list");
7+
mylist.empty();
8+
mylist.append($("<option>", {value: "../" + cur_ver, text: name}));
9+
$.getJSON("../versions.json", function(obj) {
10+
$.each(obj.versions, function() {
11+
if (this != cur_ver) {
12+
name = this.startsWith('v') ? this.substring(1) : this;
13+
mylist.append($("<option>", {value: "../" + this, text: name}));
14+
}
15+
});
16+
});
17+
});

docs/_templates/footer.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% extends "!footer.html" %}
22
{% block extrafooter %}
3+
{{ super() }}
34
<script>
45
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
56
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -8,10 +9,10 @@
89

910
ga('create', 'UA-92978945-1', 'auto');
1011
ga('send', 'pageview');
11-
1212
</script>
13+
<script type="text/javascript" src="_static/jquery.js"></script>
14+
<script type="text/javascript" src="_static/pop_ver.js"></script>
1315
<p>Do you enjoy using MetPy?
1416
<a href="https://saythanks.io/to/unidata" class="btn btn-neutral" title="Installation Guide" accesskey="n">Say Thanks!</a>
1517
</p>
16-
{{ super() }}
1718
{% endblock %}

0 commit comments

Comments
 (0)