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
15 | 15 |
import re
|
16 | 16 |
import six
|
17 | 17 |
from six.moves.urllib import parse
|
|
18 |
import string
|
18 | 19 |
import subprocess
|
19 | 20 |
|
20 | 21 |
|
|
41 | 42 |
def _html_page_context(app, pagename, templatename, context, doctree):
|
42 | 43 |
# Insert the cgit link into the template context.
|
43 | 44 |
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
|
44 | 59 |
return None
|
45 | 60 |
|
46 | 61 |
|
28 | 28 |
<p class="topless"><a href="{{ next.link|e }}"
|
29 | 29 |
title="{{ _('next chapter') }}">{{ next.title }}</a></p>
|
30 | 30 |
{%- 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 %}
|
31 | 41 |
{%- endblock %}
|
32 | 42 |
{%- block projectsource %}
|
33 | 43 |
{%- if cgit_link %}
|