From d95f3e74554b3e97ad79d3f57d698e9a0dd2c329 Mon Sep 17 00:00:00 2001 From: Bill Sacks Date: Fri, 6 Mar 2020 10:29:37 -0700 Subject: [PATCH 1/4] Allow versioned documentation with a pull-down menu This changes the documentation theme to use the readthedocs theme, with some JavaScript that provides capabilities for a dropdown menu allowing you to select between different versions. This mimics the changes in https://github.com/ESCOMP/CISM-wrapper/pull/23 The changes in this commit assume that sphinx_rtd_theme is installed in _themes. However, we are not going to do this here: instead, we'll rely on a pip install of an appropriate branch of sphinx_rtd_theme, using: pip install git+https://github.com/esmci/sphinx_rtd_theme.git@version-dropdown-with-fixes A follow-up commit will fix that. --- doc/source/_static | 0 doc/source/_static/pop_ver.js | 37 +++++++++++++++++++++++++++++++ doc/source/_templates/footer.html | 5 +++++ doc/source/_templates/layout.html | 3 +++ doc/source/conf.py | 23 ++++++++++++++----- 5 files changed, 62 insertions(+), 6 deletions(-) delete mode 100644 doc/source/_static create mode 100644 doc/source/_static/pop_ver.js create mode 100644 doc/source/_templates/footer.html create mode 100644 doc/source/_templates/layout.html diff --git a/doc/source/_static b/doc/source/_static deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/doc/source/_static/pop_ver.js b/doc/source/_static/pop_ver.js new file mode 100644 index 00000000000..b8c58658a82 --- /dev/null +++ b/doc/source/_static/pop_ver.js @@ -0,0 +1,37 @@ +$(document).ready(function() { + /* For a URL that looks like + https://blah.github.io/versions/VERSIONFOO/html/bar/index.html, set cur_version_dir to + 'VERSIONFOO' (i.e., the portion of the path following 'versions'). + */ + var proj_end = document.baseURI.indexOf("versions") + 9; + var end = document.baseURI.indexOf("/", proj_end); + var cur_version_dir = document.baseURI.substring(proj_end, end); + var mylist = $("#version-list"); + mylist.empty(); + $.getJSON(version_json_loc, function(data) { + if (data.hasOwnProperty(cur_version_dir)) { + /* First add the current version so that it appears first in the drop-down + menu and starts as the selected element of the menu. If you click on the + current version, you should stay at the current page. + + The conditional around this block should generally be true, but we check it + just in case the current version is missing from the versions.json file for + some reason. + */ + cur_version_name = data[cur_version_dir]; + mylist.append($("