From 99b28893f25226293ab8b9d4402dfa98d8ea0368 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Tue, 3 Dec 2024 21:33:43 +0300 Subject: [PATCH] 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. --- sphinx_rtd_theme/breadcrumbs.html | 64 +++++++++++++++---------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/sphinx_rtd_theme/breadcrumbs.html b/sphinx_rtd_theme/breadcrumbs.html index bd45b6d7c..d18251219 100644 --- a/sphinx_rtd_theme/breadcrumbs.html +++ b/sphinx_rtd_theme/breadcrumbs.html @@ -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 -#} + {{ _('Edit on GitHub') }} + {%- else %} + {{ _('Edit on GitHub') }} + {%- 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 %} + {{ _('Edit on Bitbucket') }} + {%- else %} + {{ _('Edit on Bitbucket') }} + {%- 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 %} + {{ _('Edit on GitLab') }} + {%- else %} + {{ _('Edit on GitLab') }} + {%- endif %} + {% endset %} {%- endif %} {%- set display_vcs_links = display_vcs_links if display_vcs_links is defined else True %} @@ -31,27 +44,12 @@ {%- block breadcrumbs_aside %}
  • {%- if hasdoc(pagename) and display_vcs_links %} - {%- if display_github %} - {%- if check_meta and 'github_url' in meta %} - - {{ _('Edit on GitHub') }} - {%- else %} - {{ _('Edit on GitHub') }} - {%- endif %} - {%- elif display_bitbucket %} - {%- if check_meta and 'bitbucket_url' in meta %} - - {{ _('Edit on Bitbucket') }} - {%- else %} - {{ _('Edit on Bitbucket') }} - {%- endif %} - {%- elif display_gitlab %} - {%- if check_meta and 'gitlab_url' in meta %} - - {{ _('Edit on GitLab') }} - {%- else %} - {{ _('Edit on GitLab') }} - {%- endif %} + {%- if github_sourcelink %} + {{ github_sourcelink }} + {%- elif bitbucket_sourcelink %} + {{ bitbucket_sourcelink }} + {%- elif gitlab_sourcelink %} + {{ gitlab_sourcelink }} {%- elif show_source and source_url_prefix %} {{ _('View page source') }} {%- elif show_source and has_source and sourcename %}