diff options
author | John Dickinson <me@not.mn> | 2016-05-06 16:49:48 -0700 |
---|---|---|
committer | John Dickinson <me@not.mn> | 2016-05-09 14:35:20 -0700 |
commit | 75cfb9f93b3560ff412cae4de3029157c14b258f (patch) | |
tree | fb41ce3ef78d984bde75dd5dd3163e94a34c24d5 | |
parent | 8084f2a4685f20f5fce60d292d2771e7c58fb701 (diff) | |
download | oslosphinx-75cfb9f93b3560ff412cae4de3029157c14b258f.tar.gz |
add recent versions links to sidebar
The last five tags (that start with a number) are used as version
numbers and linked to. This updates the sphinx extension so that
every user of the theme gets this info automatically with no need
to update the conf.py on a per-project basis.
Change-Id: I9bf17872bd23bed3cab9b5e2349d615c7001cb66
-rw-r--r-- | oslosphinx/__init__.py | 15 | ||||
-rw-r--r-- | oslosphinx/theme/openstack/layout.html | 10 |
2 files changed, 25 insertions, 0 deletions
diff --git a/oslosphinx/__init__.py b/oslosphinx/__init__.py index 77f962f..4613c89 100644 --- a/oslosphinx/__init__.py +++ b/oslosphinx/__init__.py @@ -16,6 +16,7 @@ import os import re import six from six.moves.urllib import parse +import string import subprocess @@ -42,6 +43,20 @@ def _guess_cgit_link(): def _html_page_context(app, pagename, templatename, context, doctree): # Insert the cgit link into the template context. context['cgit_link'] = app.config.oslosphinx_cgit_link + + git_cmd = ["git", "tag"] + try: + raw_version_list = subprocess.Popen( + git_cmd, stdout=subprocess.PIPE).communicate()[0] + except OSError: + app.warn('Cannot get tags from git repository. ' + 'Not setting "other_versions".') + raw_version_list = '' + + # grab last five that start with a number and reverse the order + other_versions = [t for t in raw_version_list.split('\n') + if t and t[0] in string.digits][:-6:-1] + context['other_versions'] = other_versions return None diff --git a/oslosphinx/theme/openstack/layout.html b/oslosphinx/theme/openstack/layout.html index 512ab3f..ab8e7db 100644 --- a/oslosphinx/theme/openstack/layout.html +++ b/oslosphinx/theme/openstack/layout.html @@ -30,6 +30,16 @@ title="{{ _('next chapter') }}">{{ next.title }}</a></p> {%- endif %} {%- endblock %} + {%- block otherversions %} + {%- if other_versions %} + <h3>{{ _('Other Versions') }}</h3> + <ul class="this-page-menu"> + {%- for ver in other_versions: %} + <li><a href="/{{ver}}" rel="nofollow">{{ ver }}</a></li> + {%- endfor %} + </ul> + {%- endif %} + {%- endblock %} {%- block projectsource %} {%- if cgit_link %} <h3>{{ _('Project Source') }}</h3> |