Skip to content

Commit

Permalink
Rewrite "Edit on ..." template logic for readability
Browse files Browse the repository at this point in the history
If `display_...` is not set, do not show anything.
If some `..._url` is defined on document level, use that.
  • Loading branch information
abitrolly committed Dec 3, 2024
1 parent 8d4d394 commit eb7a151
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions sphinx_rtd_theme/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
{%- if meta is defined and meta is not none %}
{%- set check_meta = True %}
{%- else %}
{%- set check_meta = False %}
{%- endif %}

{%- if check_meta and 'github_url' in meta %}
{%- set display_github = True %}
{%- if display_github %}
{% set github_sourcelink %}
{%- if meta and 'github_url' in meta %}
{#- "meta" or "front matter" is data defined inside a page -#}
<a href="{{ meta['github_url'] }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
{%- else %}
<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>
{%- endif %}
{% endset %}
{%- endif %}

{%- if check_meta and 'bitbucket_url' in meta %}
{%- set display_bitbucket = True %}
{%- if display_bitbucket %}
{% set bitbucket_sourcelink %}
{%- if meta and 'bitbucket_url' in meta %}
<a href="{{ meta['bitbucket_url'] }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
{%- else %}
<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>
{%- endif %}
{% endset %}
{%- endif %}

{%- if check_meta and 'gitlab_url' in meta %}
{%- set display_gitlab = True %}
{%- if display_gitlab %}
{% set gitlab_sourcelink %}
{%- if meta and 'gitlab_url' in meta %}
<a href="{{ meta['gitlab_url'] }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
{%- else %}
<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>
{%- endif %}
{% endset %}
{%- endif %}

{%- set display_vcs_links = display_vcs_links if display_vcs_links is defined else True %}
Expand All @@ -31,27 +44,12 @@
{%- block breadcrumbs_aside %}
<li class="wy-breadcrumbs-aside">
{%- if hasdoc(pagename) and display_vcs_links %}
{%- if display_github %}
{%- if check_meta and 'github_url' in meta %}
<!-- User defined GitHub URL -->
<a href="{{ meta['github_url'] }}" class="fa fa-github"> {{ _('Edit on GitHub') }}</a>
{%- else %}
<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>
{%- endif %}
{%- if github_sourcelink %}
{{ github_sourcelink }}
{%- elif display_bitbucket %}
{%- if check_meta and 'bitbucket_url' in meta %}
<!-- User defined Bitbucket URL -->
<a href="{{ meta['bitbucket_url'] }}" class="fa fa-bitbucket"> {{ _('Edit on Bitbucket') }}</a>
{%- else %}
<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>
{%- endif %}
{{ bitbucket_sourcelink }}
{%- elif display_gitlab %}
{%- if check_meta and 'gitlab_url' in meta %}
<!-- User defined GitLab URL -->
<a href="{{ meta['gitlab_url'] }}" class="fa fa-gitlab"> {{ _('Edit on GitLab') }}</a>
{%- else %}
<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>
{%- endif %}
{{ gitlab_sourcelink }}
{%- elif show_source and source_url_prefix %}
<a href="{{ source_url_prefix }}{{ pagename }}{{ page_source_suffix }}">{{ _('View page source') }}</a>
{%- elif show_source and has_source and sourcename %}
Expand Down

0 comments on commit eb7a151

Please sign in to comment.