From efec9c68fe2fcc51c147c0b20228a57be60ff2db Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 24 Sep 2015 13:21:42 +0000 Subject: add link to project source in navigation sidebar Change-Id: I841f0e63259d6b79c55b223c8e7266c8520a668d Closes-Bug: #1426898 --- oslosphinx/__init__.py | 24 ++++++++++++++++++++++++ oslosphinx/theme/openstack/layout.html | 9 +++++++++ 2 files changed, 33 insertions(+) diff --git a/oslosphinx/__init__.py b/oslosphinx/__init__.py index 4a238c0..24c7f40 100644 --- a/oslosphinx/__init__.py +++ b/oslosphinx/__init__.py @@ -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): diff --git a/oslosphinx/theme/openstack/layout.html b/oslosphinx/theme/openstack/layout.html index 2272675..512ab3f 100644 --- a/oslosphinx/theme/openstack/layout.html +++ b/oslosphinx/theme/openstack/layout.html @@ -30,6 +30,15 @@ title="{{ _('next chapter') }}">{{ next.title }}

{%- endif %} {%- endblock %} + {%- block projectsource %} + {%- if cgit_link %} +

{{ _('Project Source') }}

+ + {%- endif %} + {%- endblock %} {%- block sidebarsourcelink %} {%- if show_source and has_source and sourcename %}

{{ _('This Page') }}

-- cgit v1.2.1