Skip to content

Commit 8f1783a

Browse files
committed
"Improve page" links for examples and tutorials
Adds the sphinx-gallery configuration to the template so we can link to the Github edit page for the gallery .py files. The template also identifies the index.html files and directs them to the README.txt files.
1 parent 3ce6953 commit 8f1783a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/_templates/breadcrumbs.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
{% block breadcrumbs_aside %}
77
<li class="source-link">
88
{% if hasdoc(pagename) %}
9-
{% if pagename.startswith("api/") or pagename.startswith("tutorials/") or pagename.startswith("examples/")%}
9+
{% if pagename.startswith(api_dir) %}
1010
{% set title = "Suggested improvement for " + pagename %}
1111
{% set body = "Please describe what could be improved about this page or the typo/mistake that you found:" %}
1212
<a href="https://github.com/{{ github_repo }}/issues/new?title={{ title|urlencode }}&body={{ body|urlencode }}"
1313
class="fa fa-github"> Improve this page</a>
14+
{% elif pagename.split("/")[0] in galleries %}
15+
{% set gallery_path = gallery_dir[pagename.split("/")[0]] %}
16+
{% set example_script = pagename|replace(pagename.split("/")[0], gallery_dir[pagename.split("/")[0]]) %}
17+
{% if pagename.split("/")[-1] == "index" %}
18+
{% set example_script = example_script|replace("index", "README.txt") %}
19+
{% else %}
20+
{% set example_script = example_script + ".py" %}
21+
{% endif %}
22+
<a href="https://github.com/{{ github_repo }}/edit/{{ github_version }}/{{ doc_path }}/{{ example_script }}"
23+
class="fa fa-github"> Improve this page</a>
1424
{% else %}
1525
<a href="https://github.com/{{ github_repo }}/edit/{{ github_version }}/{{ doc_path }}/{{ pagename }}{{ suffix }}"
1626
class="fa fa-github"> Improve this page</a>

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ def setup(app):
175175
# links to the Github repository sources and issues
176176
html_context = {
177177
'doc_path': 'docs',
178+
'galleries': sphinx_gallery_conf['gallery_dirs'],
179+
'gallery_dir': dict(zip(sphinx_gallery_conf['gallery_dirs'],
180+
sphinx_gallery_conf['examples_dirs'])),
181+
'api_dir': 'api/generated',
178182
'github_repo': 'Unidata/MetPy',
179183
'github_version': 'master', # Make changes to the master branch
180184
}

0 commit comments

Comments
 (0)