forked from splunk/public-o11y-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
olly_on_git_hub.py
29 lines (21 loc) · 886 Bytes
/
olly_on_git_hub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import warnings
def olly_get_github_url(app, view, path):
return 'https://github.com/{repo}/{view}/{branch}/{path}'.format(
repo=app.config.olly_on_github_repo,
view=view,
branch=app.config.olly_on_github_branch,
path=path)
def html_page_context(app, pagename, templatename, context, doctree):
if templatename != 'page.html':
return
if not app.config.olly_on_github_repo:
warnings.warn("olly_on_github_repo not specified")
return
path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
show_url = olly_get_github_url(app, 'edit', path)
context['olly_on_github_url'] = show_url
def setup(app):
app.add_config_value('olly_on_github_repo', '', True)
app.add_config_value('olly_on_github_branch', 'main', True)
app.connect('html-page-context', html_page_context)