add link to project source in navigation sidebar
Change-Id: I841f0e63259d6b79c55b223c8e7266c8520a668d Closes-Bug: #1426898
This commit is contained in:
parent
e9e52bd118
commit
efec9c68fe
|
@ -13,6 +13,28 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
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):
|
def builder_inited(app):
|
||||||
|
@ -33,6 +55,8 @@ def builder_inited(app):
|
||||||
# the templates and theme.
|
# the templates and theme.
|
||||||
if hasattr(app.builder, 'init_templates'):
|
if hasattr(app.builder, 'init_templates'):
|
||||||
app.builder.init_templates()
|
app.builder.init_templates()
|
||||||
|
# Register our page context additions
|
||||||
|
app.connect('html-page-context', _html_page_context)
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
|
|
|
@ -30,6 +30,15 @@
|
||||||
title="{{ _('next chapter') }}">{{ next.title }}</a></p>
|
title="{{ _('next chapter') }}">{{ next.title }}</a></p>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endblock %}
|
{%- 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 %}
|
{%- block sidebarsourcelink %}
|
||||||
{%- if show_source and has_source and sourcename %}
|
{%- if show_source and has_source and sourcename %}
|
||||||
<h3>{{ _('This Page') }}</h3>
|
<h3>{{ _('This Page') }}</h3>
|
||||||
|
|
Loading…
Reference in New Issue