]> git.proxmox.com Git - ceph.git/blob - ceph/doc/_ext/edit_on_github.py
update source to 12.2.11
[ceph.git] / ceph / doc / _ext / edit_on_github.py
1 """
2 Adapted from https://gist.github.com/mgedmin/6052926
3
4 Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the
5 sidebar.
6
7 Loosely based on https://github.com/astropy/astropy/pull/347
8 """
9
10 import os
11 import warnings
12
13
14 __licence__ = 'BSD (3 clause)'
15
16
17 def get_github_url(app, view, path):
18 return 'https://github.com/{project}/{view}/{branch}/doc/{path}'.format(
19 project=app.config.edit_on_github_project,
20 view=view,
21 branch=app.config.edit_on_github_branch,
22 path=path)
23
24
25 def html_page_context(app, pagename, templatename, context, doctree):
26 if templatename != 'page.html':
27 return
28
29 if not app.config.edit_on_github_project:
30 warnings.warn("edit_on_github_project not specified")
31 return
32
33 path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
34 show_url = get_github_url(app, 'blob', path)
35 edit_url = get_github_url(app, 'edit', path)
36
37 context['show_on_github_url'] = show_url
38 context['edit_on_github_url'] = edit_url
39
40 def setup(app):
41 app.add_config_value('edit_on_github_project', '', True)
42 app.add_config_value('edit_on_github_branch', 'master', True)
43 app.connect('html-page-context', html_page_context)