Skip to content

Commit

Permalink
Merge pull request ESMCI#3439 from billsacks/versioned_docs3
Browse files Browse the repository at this point in the history
Documentation: provide a version dropdown menu and change theme

The documentation of cime is starting to diverge on the various
important branches (master, maint-5.6, and ufs_release_v1.0). This PR,
along with similar PRs for maint-5.6 and ufs_release_v1.0, and some
changes to the gh-pages branch, support having versioned documentation,
with a dropdown menu. This also changes the documentation theme to a
theme that supports this version dropdown. Note that this requires a
branch of the sphinx_rtd_theme; I will update the cime wiki on building
the documentation to note the new pip install step needed for that. (See
below for more details.)

At a high level, the way the versioned documentation works is to have
separate subdirectories in the gh-pages branch for each version of the
documentation we want to support. There is then a bit of JavaScript code
which uses a json file in the gh-pages branch to determine which
versions exist and how these should be named in the dropdown menu. This
changes the documentation build process slightly; I will update the wiki
to reflect these changes.

@mvertens and I made the various changes that you can see in
`doc/source` in this PR, which mainly borrowed from
ESCOMP/CISM-wrapper#23. That, in turn, is a
slight modification of an implementation provided by @MNLevy for the
MARBL documentation, which in turn borrowed from an implementation put
together by Unidata (credit where credit is due).

As mentioned above, I am not aware of out-of-the-box support for a
version pull-down in out-of-the-box sphinx themes (though the last time
I looked was in Fall, 2018, so there may be something available
now). However, support for a version dropdown exists in an open PR in
the sphinx readthedocs theme repository:
readthedocs/sphinx_rtd_theme#438. I have pushed
this branch to a new repository in ESMCI
(https://github.com/ESMCI/sphinx_rtd_theme) to facilitate long-term
maintenance of this branch in case it disappears from the official
sphinx_rtd_theme repository. I have also cherry-picked a commit onto
that branch, which is needed to fix search functionality in sphinx1.8
(from readthedocs/sphinx_rtd_theme#672) (which
is another reason for maintaining our own copy of this branch). The
branch in this repository is now named version-dropdown-with-fixes
(branching off of the version-dropdown branch in the sphinx_rtd_theme
repository). I will update the wiki to give the additional pip install
command needed to install this repository before doing the build. In the
long-term, I am a little concerned about using this theme that isn't
showing any signs of being merged to the main branch of the readthedocs
theme, but this has been working for us in other projects for the last 2
years, so I feel this is a reasonable approach in the short-medium term.

A few changes were also needed in the gh-pages branch:

- A `versions` directory was introduced at the top level, with
  subdirectories for each documentation version we want to support. We
  are using the convention that these subdirectories should have names
  that match the corresponding cime branches, to avoid uncertainty.

- A top-level index.html page was introduced that redirects to the
  master version of the documentation:

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="refresh" content="0; url=versions/master/html/index.html" />
  </head>
</html>
```

- Other than those files and an empty `.nojekyll` file, everything else
  was removed from the top level directory of the documentation.

- In the versions directory, we also introduced a `versions.json`
  file. This lists the versions and provides a mapping between directory
  names and the names used in the pull-down menu:

```json
{
    "master": "master",
    "maint-5.6": "cime5.6",
    "ufs_release_v1.0": "ufs_release_v1.0"
}
```

- The complete contents of each version subdirectory are generated by
  the documentation build script. Thus, it is safe to remove the
  contents of (e.g.) `versions/master/` before rebuilding the
  documentation for that version. The documentation build is done
  similarly to before, but now providing a BUILDDIR argument to the make
  command in order to build in the correct subdirectory. For example,
  when building the documentation for master, you would provide
  `BUILDDIR=/path/to/cime_gh_pages_repo/versions/master/`.

Test suite: none
Test baseline: n/a
Test namelist changes: none
Test status: bit for bit

Fixes none

User interface changes?: none

Update gh-pages html (Y/N)?: Y (already done)

Code review:
  • Loading branch information
billsacks committed Mar 14, 2020
2 parents 38c2b9f + 758a5b8 commit 4f18807
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 20 deletions.
28 changes: 13 additions & 15 deletions doc/README
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

This requires Sphinx v1.7 or greater.
This requires Sphinx v1.7 or greater, as well as some add-ons, which can
be installed with:

pip install sphinx
pip install sphinxcontrib-programoutput
pip install git+https://github.com/esmci/sphinx_rtd_theme.git@version-dropdown-with-fixes

Check the sphinx version as follows:

>sphinx-build --version

The documentation source is stored with the CIME master code base. However,
the built html files are stored seperately in the orphan gh-pages branch
the built html files are stored separately in the orphan gh-pages branch
and can be viewed from a browser at URL:

http://esmci.github.io/cime
Expand All @@ -19,17 +24,10 @@ https://github.com/ESMCI/cime/wiki/Working-with-Sphinx-and-reStructuredText
Use the following commands to auto-build the html documentation from the main
cime/doc directory:

>make clean
>make api
>make html

To copy the html to the orphan gh-pages, follow these steps:

>git clone -b gh-pages https://github.com/ESMCI/cime.git cime.gh-pages
>cd cime.gh-pages
>rm -rf *
>cp -R /path/to/cime-master/doc/build/html/* .
>git commit -m 'update HTML for PR #...'
>git push origin gh-pages

make clean
make api
make html

To publish the docs to the orphan gh-pages branch, follow the steps in
https://github.com/ESMCI/cime/wiki/Working-with-Sphinx-and-reStructuredText
to ensure proper versioning of the documentation.
Empty file removed doc/source/_static
Empty file.
37 changes: 37 additions & 0 deletions doc/source/_static/pop_ver.js
Original file line number Diff line number Diff line change
@@ -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($("<option>", {value: document.baseURI, text: cur_version_name}));
}
// Now add the other versions
$.each(data, function(version_dir, version_name) {
if (version_dir != cur_version_dir) {
/* If you click on a different version, you should go to the root of the
documentation for that version. This assumes paths like
https://blah.github.io/versions/VERSIONFOO/html/bar/index.html. So we
need to go up two levels from the URL_ROOT (html) to then go back down
into the appropriate version's html directory.
*/
mylist.append($("<option>", {value: DOCUMENTATION_OPTIONS.URL_ROOT + '../../' + version_dir + '/html', text: version_name}));
}
});
});
});
5 changes: 5 additions & 0 deletions doc/source/_templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends "!footer.html" %}
{% block extrafooter %}
{{ super() }}
<script>var version_json_loc = "{{ pathto('../../versions.json', 1) }}";</script>
{% endblock %}
3 changes: 3 additions & 0 deletions doc/source/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "!layout.html" %}

{% set script_files = script_files + ["_static/pop_ver.js"] %}
22 changes: 17 additions & 5 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#
import os
import sys
# Note that we need a specific version of sphinx_rtd_theme. This can be obtained with:
# pip install git+https://github.com/esmci/sphinx_rtd_theme.git@version-dropdown-with-fixes
import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('../../scripts/lib'))
sys.path.insert(1, os.path.abspath('../../scripts'))

Expand Down Expand Up @@ -64,9 +67,9 @@
# built documents.
#
# The short X.Y version.
version = u'5.6'
version = u'master'
# The full version, including alpha/beta/rc tags.
release = u'5.6'
release = u'master'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -94,15 +97,24 @@
#
#html_theme = 'alabaster'
#html_theme = 'bizstyle'
html_theme = 'classic'
#html_theme = 'sphinx_rtd_theme'
#html_theme = 'classic'
#html_theme = 'sphinxdoc'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {"stickysidebar": "true"}
#html_theme_options = {"stickysidebar": "true"}

# The 'versions' option needs to have at least two versions to work, but it doesn't need
# to have all versions: others will be added dynamically. Note that this maps from version
# names to html links. The current version can link to the current location (i.e., do
# nothing). For the other version, we just add a place-holder; its name and value are
# unimportant because these versions will get replaced dynamically.
html_theme_options = {}
html_theme_options['versions'] = {version: ''}
html_theme_options['versions']['[placeholder]'] = ''

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down

0 comments on commit 4f18807

Please sign in to comment.