Codebase list oslo-sphinx / 75cfb9f
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 John Dickinson 8 years ago
2 changed file(s) with 25 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1515 import re
1616 import six
1717 from six.moves.urllib import parse
18 import string
1819 import subprocess
1920
2021
4142 def _html_page_context(app, pagename, templatename, context, doctree):
4243 # Insert the cgit link into the template context.
4344 context['cgit_link'] = app.config.oslosphinx_cgit_link
45
46 git_cmd = ["git", "tag"]
47 try:
48 raw_version_list = subprocess.Popen(
49 git_cmd, stdout=subprocess.PIPE).communicate()[0]
50 except OSError:
51 app.warn('Cannot get tags from git repository. '
52 'Not setting "other_versions".')
53 raw_version_list = ''
54
55 # grab last five that start with a number and reverse the order
56 other_versions = [t for t in raw_version_list.split('\n')
57 if t and t[0] in string.digits][:-6:-1]
58 context['other_versions'] = other_versions
4459 return None
4560
4661
2828 <p class="topless"><a href="{{ next.link|e }}"
2929 title="{{ _('next chapter') }}">{{ next.title }}</a></p>
3030 {%- endif %}
31 {%- endblock %}
32 {%- block otherversions %}
33 {%- if other_versions %}
34 <h3>{{ _('Other Versions') }}</h3>
35 <ul class="this-page-menu">
36 {%- for ver in other_versions: %}
37 <li><a href="/{{ver}}" rel="nofollow">{{ ver }}</a></li>
38 {%- endfor %}
39 </ul>
40 {%- endif %}
3141 {%- endblock %}
3242 {%- block projectsource %}
3343 {%- if cgit_link %}