Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
add recent versions links to sidebar
Browse files Browse the repository at this point in the history
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
  • Loading branch information
notmyname committed May 9, 2016
1 parent 8084f2a commit 75cfb9f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions oslosphinx/__init__.py
Expand Up @@ -16,6 +16,7 @@
import re
import six
from six.moves.urllib import parse
import string
import subprocess


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


Expand Down
10 changes: 10 additions & 0 deletions oslosphinx/theme/openstack/layout.html
Expand Up @@ -30,6 +30,16 @@ <h4>{{ _('Next topic') }}</h4>
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>
Expand Down

0 comments on commit 75cfb9f

Please sign in to comment.