Codebase list oslo-sphinx / efec9c6
add link to project source in navigation sidebar Change-Id: I841f0e63259d6b79c55b223c8e7266c8520a668d Closes-Bug: #1426898 Doug Hellmann 8 years ago
2 changed file(s) with 33 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1212 # under the License.
1313
1414 import os
15 import subprocess
16 import urlparse
17
18
19 CGIT_BASE = 'http://git.openstack.org/cgit/'
20 _cgit_link = None
21
22
23 def _html_page_context(app, pagename, templatename, context, doctree):
24 global _cgit_link
25 if _cgit_link is None:
26 try:
27 git_remote = subprocess.check_output(
28 ['git', 'config', '--local', '--get', 'remote.origin.url']
29 )
30 except subprocess.CheckedProcessException:
31 _cgit_link = 'unknown'
32 else:
33 parsed = urlparse.urlparse(git_remote)
34 _cgit_link = CGIT_BASE + parsed.path.lstrip('/')
35 context['cgit_link'] = _cgit_link
36 return context
1537
1638
1739 def builder_inited(app):
3254 # the templates and theme.
3355 if hasattr(app.builder, 'init_templates'):
3456 app.builder.init_templates()
57 # Register our page context additions
58 app.connect('html-page-context', _html_page_context)
3559
3660
3761 def setup(app):
2828 <p class="topless"><a href="{{ next.link|e }}"
2929 title="{{ _('next chapter') }}">{{ next.title }}</a></p>
3030 {%- endif %}
31 {%- endblock %}
32 {%- block projectsource %}
33 {%- if cgit_link %}
34 <h3>{{ _('Project Source') }}</h3>
35 <ul class="this-page-menu">
36 <li><a href="{{cgit_link}}"
37 rel="nofollow">{{ _('Project Source') }}</a></li>
38 </ul>
39 {%- endif %}
3140 {%- endblock %}
3241 {%- block sidebarsourcelink %}
3342 {%- if show_source and has_source and sourcename %}