]>
git.proxmox.com Git - ceph.git/blob - ceph/doc/_ext/edit_on_github.py
2 Adapted from https://gist.github.com/mgedmin/6052926
4 Sphinx extension to add ReadTheDocs-style "Edit on GitHub" links to the
7 Loosely based on https://github.com/astropy/astropy/pull/347
14 __licence__
= 'BSD (3 clause)'
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
,
21 branch
=app
.config
.edit_on_github_branch
,
25 def html_page_context(app
, pagename
, templatename
, context
, doctree
):
26 if templatename
!= 'page.html':
29 if not app
.config
.edit_on_github_project
:
30 warnings
.warn("edit_on_github_project not specified")
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
)
37 context
['show_on_github_url'] = show_url
38 context
['edit_on_github_url'] = edit_url
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
)