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
This commit is contained in:
John Dickinson 2016-05-06 16:49:48 -07:00
parent 8084f2a468
commit 75cfb9f93b
2 changed files with 25 additions and 0 deletions

View File

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

View File

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