diff options
-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> |