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 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 @@

{{ _('Next topic') }}

title="{{ _('next chapter') }}">{{ next.title }}

{%- endif %} {%- endblock %} + {%- block otherversions %} + {%- if other_versions %} +

{{ _('Other Versions') }}

+ + {%- endif %} + {%- endblock %} {%- block projectsource %} {%- if cgit_link %}

{{ _('Project Source') }}