diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-09-25 09:55:19 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-09-25 09:55:19 +0000 |
commit | 6ffe7dd4f3b99101d814d8648f22f140d9c1dcdc (patch) | |
tree | 0fe7b0727876f55315f365e86edf2e0de277e17c | |
parent | 6ebaef6ba4edb4e336a23d34418519e05977e8c1 (diff) | |
parent | efec9c68fe2fcc51c147c0b20228a57be60ff2db (diff) | |
download | oslosphinx-6ffe7dd4f3b99101d814d8648f22f140d9c1dcdc.tar.gz |
Merge "add link to project source in navigation sidebar"
-rw-r--r-- | oslosphinx/__init__.py | 24 | ||||
-rw-r--r-- | oslosphinx/theme/openstack/layout.html | 9 |
2 files changed, 33 insertions, 0 deletions
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 }}</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> |