add link to project source in navigation sidebar
Change-Id: I841f0e63259d6b79c55b223c8e7266c8520a668d
Closes-Bug: #1426898
Doug Hellmann
8 years ago
12 | 12 |
# under the License.
|
13 | 13 |
|
14 | 14 |
import os
|
|
15 |
import subprocess
|
|
16 |
import urlparse
|
|
17 |
|
|
18 |
|
|
19 |
CGIT_BASE = 'http://git.openstack.org/cgit/'
|
|
20 |
_cgit_link = None
|
|
21 |
|
|
22 |
|
|
23 |
def _html_page_context(app, pagename, templatename, context, doctree):
|
|
24 |
global _cgit_link
|
|
25 |
if _cgit_link is None:
|
|
26 |
try:
|
|
27 |
git_remote = subprocess.check_output(
|
|
28 |
['git', 'config', '--local', '--get', 'remote.origin.url']
|
|
29 |
)
|
|
30 |
except subprocess.CheckedProcessException:
|
|
31 |
_cgit_link = 'unknown'
|
|
32 |
else:
|
|
33 |
parsed = urlparse.urlparse(git_remote)
|
|
34 |
_cgit_link = CGIT_BASE + parsed.path.lstrip('/')
|
|
35 |
context['cgit_link'] = _cgit_link
|
|
36 |
return context
|
15 | 37 |
|
16 | 38 |
|
17 | 39 |
def builder_inited(app):
|
|
32 | 54 |
# the templates and theme.
|
33 | 55 |
if hasattr(app.builder, 'init_templates'):
|
34 | 56 |
app.builder.init_templates()
|
|
57 |
# Register our page context additions
|
|
58 |
app.connect('html-page-context', _html_page_context)
|
35 | 59 |
|
36 | 60 |
|
37 | 61 |
def setup(app):
|
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 projectsource %}
|
|
33 |
{%- if cgit_link %}
|
|
34 |
<h3>{{ _('Project Source') }}</h3>
|
|
35 |
<ul class="this-page-menu">
|
|
36 |
<li><a href="{{cgit_link}}"
|
|
37 |
rel="nofollow">{{ _('Project Source') }}</a></li>
|
|
38 |
</ul>
|
|
39 |
{%- endif %}
|
31 | 40 |
{%- endblock %}
|
32 | 41 |
{%- block sidebarsourcelink %}
|
33 | 42 |
{%- if show_source and has_source and sourcename %}
|