Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb7a151

Browse files
committedDec 3, 2024·
Rewrite "Edit on ..." template logic for readability
If `display_...` is not set, do not show anything. If some `..._url` is defined on document level, use that.
1 parent 8d4d394 commit eb7a151

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed
 

‎sphinx_rtd_theme/breadcrumbs.html

+29-31
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
{%- if meta is defined and meta is not none %}
2-
{%- set check_meta = True %}
3-
{%- else %}
4-
{%- set check_meta = False %}
5-
{%- endif %}
6-
7-
{%- if check_meta and 'github_url' in meta %}
8-
{%- set display_github = True %}
1+
{%- if display_github %}
2+
{% set github_sourcelink %}
3+
{%- if meta and 'github_url' in meta %}
4+
{#- "meta" or "front matter" is data defined inside a page -#}
5+
<a href="{{ meta['github_url'] }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
6+
{%- else %}
7+
<a href="https://{{ github_host|default("github.com") }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode or "blob" }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
8+
{%- endif %}
9+
{% endset %}
910
{%- endif %}
1011

11-
{%- if check_meta and 'bitbucket_url' in meta %}
12-
{%- set display_bitbucket = True %}
12+
{%- if display_bitbucket %}
13+
{% set bitbucket_sourcelink %}
14+
{%- if meta and 'bitbucket_url' in meta %}
15+
<a href="{{ meta['bitbucket_url'] }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
16+
{%- else %}
17+
<a href="https://bitbucket.org/{{ bitbucket_user }}/{{ bitbucket_repo }}/src/{{ bitbucket_version}}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}?mode={{ theme_vcs_pageview_mode or "view" }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
18+
{%- endif %}
19+
{% endset %}
1320
{%- endif %}
1421

15-
{%- if check_meta and 'gitlab_url' in meta %}
16-
{%- set display_gitlab = True %}
22+
{%- if display_gitlab %}
23+
{% set gitlab_sourcelink %}
24+
{%- if meta and 'gitlab_url' in meta %}
25+
<a href="{{ meta['gitlab_url'] }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
26+
{%- else %}
27+
<a href="https://{{ gitlab_host|default("gitlab.com") }}/{{ gitlab_user }}/{{ gitlab_repo }}/{{ theme_vcs_pageview_mode or "blob" }}/{{ gitlab_version }}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
28+
{%- endif %}
29+
{% endset %}
1730
{%- endif %}
1831

1932
{%- set display_vcs_links = display_vcs_links if display_vcs_links is defined else True %}
@@ -31,27 +44,12 @@
3144
{%- block breadcrumbs_aside %}
3245
<li class="wy-breadcrumbs-aside">
3346
{%- if hasdoc(pagename) and display_vcs_links %}
34-
{%- if display_github %}
35-
{%- if check_meta and 'github_url' in meta %}
36-
<!-- User defined GitHub URL -->
37-
<a href="{{ meta['github_url'] }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
38-
{%- else %}
39-
<a href="https://{{ github_host|default("github.com") }}/{{ github_user }}/{{ github_repo }}/{{ theme_vcs_pageview_mode or "blob" }}/{{ github_version }}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
40-
{%- endif %}
47+
{%- if github_sourcelink %}
48+
{{ github_sourcelink }}
4149
{%- elif display_bitbucket %}
42-
{%- if check_meta and 'bitbucket_url' in meta %}
43-
<!-- User defined Bitbucket URL -->
44-
<a href="{{ meta['bitbucket_url'] }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
45-
{%- else %}
46-
<a href="https://bitbucket.org/{{ bitbucket_user }}/{{ bitbucket_repo }}/src/{{ bitbucket_version}}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}?mode={{ theme_vcs_pageview_mode or "view" }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
47-
{%- endif %}
50+
{{ bitbucket_sourcelink }}
4851
{%- elif display_gitlab %}
49-
{%- if check_meta and 'gitlab_url' in meta %}
50-
<!-- User defined GitLab URL -->
51-
<a href="{{ meta['gitlab_url'] }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
52-
{%- else %}
53-
<a href="https://{{ gitlab_host|default("gitlab.com") }}/{{ gitlab_user }}/{{ gitlab_repo }}/{{ theme_vcs_pageview_mode or "blob" }}/{{ gitlab_version }}{{ conf_py_path }}{{ pagename }}{{ page_source_suffix }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
54-
{%- endif %}
52+
{{ gitlab_sourcelink }}
5553
{%- elif show_source and source_url_prefix %}
5654
<a href="{{ source_url_prefix }}{{ pagename }}{{ page_source_suffix }}">{{ _('View page source') }}</a>
5755
{%- elif show_source and has_source and sourcename %}

0 commit comments

Comments
 (0)
Please sign in to comment.