Skip to content

Commit

Permalink
ENH: Add javacript to dynamically populate version chooser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dopplershift committed Oct 2, 2017
1 parent ba77131 commit cf7d532
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ci/deploy_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ if [[ "${VERSION}" != "dev" ]]; then
ln -snf ${VERSION} latest
fi

# Generate our json list of versions
echo Generating versions.json...
${TRAVIS_BUILD_DIR}/ci/gen_versions_json.py

echo Staging...
git add -A .
if [[ "${VERSION}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then
Expand Down
11 changes: 11 additions & 0 deletions ci/gen_versions_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# Copyright (c) 2017 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Generate versions.json from directory with different doc versions."""

import glob

with open('versions.json', 'wt') as version_file:
version_strings = ','.join('"{}"'.format(d) for d in glob.glob('v*.[0-9]*'))
version_file.write('{"versions":["latest","dev",' + version_strings + ']}\n')
17 changes: 17 additions & 0 deletions docs/_static/pop_ver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$(document).ready(function() {
var proj_end = document.baseURI.indexOf("MetPy") + 6;
var end = document.baseURI.indexOf("/", proj_end);
var cur_ver = document.baseURI.substring(proj_end, end);
var name = cur_ver.startsWith('v') ? cur_ver.substring(1) : cur_ver;
var mylist = $("#version-list");
mylist.empty();
mylist.append($("<option>", {value: "../" + cur_ver, text: name}));
$.getJSON("../versions.json", function(obj) {
$.each(obj.versions, function() {
if (this != cur_ver) {
name = this.startsWith('v') ? this.substring(1) : this;
mylist.append($("<option>", {value: "../" + this, text: name}));
}
});
});
});
5 changes: 3 additions & 2 deletions docs/_templates/footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "!footer.html" %}
{% block extrafooter %}
{{ super() }}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand All @@ -8,10 +9,10 @@

ga('create', 'UA-92978945-1', 'auto');
ga('send', 'pageview');

</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/pop_ver.js"></script>
<p>Do you enjoy using MetPy?
<a href="https://saythanks.io/to/unidata" class="btn btn-neutral" title="Installation Guide" accesskey="n">Say Thanks!</a>
</p>
{{ super() }}
{% endblock %}

0 comments on commit cf7d532

Please sign in to comment.