Skip to content

Commit cb8a8b7

Browse files
committed
Add edit on github link to documentation pages
Signed-off-by: Julius Härtl <[email protected]>
1 parent fd283ba commit cb8a8b7

File tree

7 files changed

+73
-7
lines changed

7 files changed

+73
-7
lines changed

_ext/edit_on_github.py

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

_shared_assets/themes/nextcloud_com/layout.html

+5
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ <h1><a href="{{ pathto(master_doc) }}">{{ project|e }}</a></h1>
205205
<div class="text-center">
206206
<p>All documentation licensed under the <a href="https://creativecommons.org/licenses/by/3.0/us/">Creative Commons Attribution 3.0 Unported license</a>.</p>
207207
<p><a href="https://github.com/nextcloud/documentation/graphs/contributors">See who contributed to our documentation/credits</a>.</p>
208+
{%- if show_source and has_source and sourcename and edit_on_github_url %}
209+
<p>Do you want to help us to improve this document?
210+
<a href="{{ edit_on_github_url }}" rel="nofollow">{{ _('Edit this page on GitHub') }} <span class="glyphicon glyphicon-pencil"></span></a>
211+
</p>
212+
{%- endif %}
208213
</div>
209214
</div>
210215
</div>

admin_manual/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Add any Sphinx extension module names here, as strings. They can be extensions
3131
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
32-
extensions = ['sphinxcontrib.phpdomain', 'sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
32+
extensions += ['sphinxcontrib.phpdomain', 'sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
3333

3434
# Add any paths that contain templates here, relative to this directory.
3535
templates_path = ['../_shared_assets/templates']
@@ -292,3 +292,5 @@
292292
'user_manual': ('https://docs.nextcloud.com/server/%s/user_manual/' % (version), '../user_manual/_build/html/com/objects.inv'),
293293
'developer_manual': ('https://docs.nextcloud.com/server/%s/developer_manual/' % (version), '../developer_manual/_build/html/com/objects.inv'),
294294
}
295+
296+
current_docs = 'admin_manual'

conf.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# global configuration for every documentation added at the end
22

3-
import os
3+
import os, sys
4+
5+
dir_path = os.path.dirname(os.path.realpath(__file__))
6+
sys.path.insert(0, os.path.abspath(dir_path + '/_ext'))
7+
8+
extensions = ['edit_on_github']
49

510
# General information about the project.
611
copyright = u'2012-2017, The Nextcloud developers'
@@ -14,11 +19,13 @@
1419
# The full version, including alpha/beta/rc tags.
1520
release = '13'
1621

17-
1822
# substitutions go here
1923
rst_epilog = '.. |version| replace:: %s' % version
2024

2125
html_context = {
2226
'doc_versions': ['11', '12', '13'],
2327
'current_doc': os.path.basename(os.getcwd()),
2428
}
29+
30+
edit_on_github_project = 'nextcloud/documentation'
31+
edit_on_github_branch = 'master'

developer_manual/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Add any Sphinx extension module names here, as strings. They can be extensions
3131
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
32-
extensions = ['sphinxcontrib.phpdomain', 'sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
32+
extensions += ['sphinxcontrib.phpdomain', 'sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
3333

3434
# Add any paths that contain templates here, relative to this directory.
3535
templates_path = ['../_shared_assets/templates']
@@ -303,6 +303,8 @@
303303
'user_manual': ('https://docs.nextcloud.com/server/%s/user_manual/' % (version), '../user_manual/_build/html/com/objects.inv'),
304304
}
305305

306+
current_docs = 'developer_manual'
307+
306308
from sphinx.builders.html import StandaloneHTMLBuilder
307309
StandaloneHTMLBuilder.supported_image_types = [
308310
'image/svg+xml',

user_manual/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Add any Sphinx extension module names here, as strings. They can be extensions
3131
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
32-
extensions = ['sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
32+
extensions += ['sphinx.ext.todo', 'rst2pdf.pdfbuilder', 'sphinx.ext.intersphinx']
3333

3434
# Add any paths that contain templates here, relative to this directory.
3535
templates_path = ['../_shared_assets/templates']
@@ -304,3 +304,4 @@
304304
'developer_manual': ('https://docs.nextcloud.com/server/%s/developer_manual/' % (version), '../developer_manual/_build/html/com/objects.inv'),
305305
}
306306

307+
current_docs = 'user_manual'

user_manual_de/conf.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Add any Sphinx extension module names here, as strings. They can be extensions
3131
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
32-
extensions = ['sphinx.ext.todo', 'rst2pdf.pdfbuilder']
32+
extensions += ['sphinx.ext.todo', 'rst2pdf.pdfbuilder']
3333

3434
# Add any paths that contain templates here, relative to this directory.
3535
templates_path = ['../_shared_assets/templates']
@@ -294,4 +294,6 @@
294294
#epub_tocdup = True
295295

296296
# Include todos?
297-
todo_include_todos = True
297+
todo_include_todos = True
298+
299+
current_docs = 'user_manual_de'

0 commit comments

Comments
 (0)