add link to project source in navigation sidebar

Change-Id: I841f0e63259d6b79c55b223c8e7266c8520a668d
Closes-Bug: #1426898
This commit is contained in:
Doug Hellmann 2015-09-24 13:21:42 +00:00
parent e9e52bd118
commit efec9c68fe
2 changed files with 33 additions and 0 deletions

View File

@ -13,6 +13,28 @@
# under the License.
import os
import subprocess
import urlparse
CGIT_BASE = 'http://git.openstack.org/cgit/'
_cgit_link = None
def _html_page_context(app, pagename, templatename, context, doctree):
global _cgit_link
if _cgit_link is None:
try:
git_remote = subprocess.check_output(
['git', 'config', '--local', '--get', 'remote.origin.url']
)
except subprocess.CheckedProcessException:
_cgit_link = 'unknown'
else:
parsed = urlparse.urlparse(git_remote)
_cgit_link = CGIT_BASE + parsed.path.lstrip('/')
context['cgit_link'] = _cgit_link
return context
def builder_inited(app):
@ -33,6 +55,8 @@ def builder_inited(app):
# the templates and theme.
if hasattr(app.builder, 'init_templates'):
app.builder.init_templates()
# Register our page context additions
app.connect('html-page-context', _html_page_context)
def setup(app):

View File

@ -30,6 +30,15 @@
title="{{ _('next chapter') }}">{{ next.title }}</a></p>
{%- endif %}
{%- endblock %}
{%- block projectsource %}
{%- if cgit_link %}
<h3>{{ _('Project Source') }}</h3>
<ul class="this-page-menu">
<li><a href="{{cgit_link}}"
rel="nofollow">{{ _('Project Source') }}</a></li>
</ul>
{%- endif %}
{%- endblock %}
{%- block sidebarsourcelink %}
{%- if show_source and has_source and sourcename %}
<h3>{{ _('This Page') }}</h3>