From b8a4d884aa6a6b570261178c7fc7856c2a097ab0 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 11 Jan 2023 15:17:18 +0100 Subject: [PATCH 1/5] Respect that dirhtml builder does not have .html in canonical URLs --- sphinx_rtd_theme/layout.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index bb0c069a2..00705259c 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -51,12 +51,22 @@ {#- CANONICAL URL (deprecated) #} {%- if theme_canonical_url and not pageurl %} - + {%- endif -%} {#- CANONICAL URL #} + {# NB! pageurl is currently a non-documented template context variable! #} + {# pageurl implementation: https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html #} {%- if pageurl %} - + {# pageurl implementation wrongly: adds .html for the dirhtml builder's pageurl #} + {# Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 #} + {# Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround #} + {% if builder == 'dirhtml' and pageurl.endswith('.html') %} + {# This expression trims away .html and adds a / #} + + {% else %} + + {% endif %} {%- endif -%} {#- JAVASCRIPTS #} From 9083bfc2305da817b8b7152394a9698f765d37bc Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 11 Jan 2023 16:24:08 +0100 Subject: [PATCH 2/5] Trim whitespaces around Jinja2 blocks --- sphinx_rtd_theme/layout.html | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 00705259c..f612bd6be 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -54,19 +54,23 @@ {%- endif -%} - {#- CANONICAL URL #} - {# NB! pageurl is currently a non-documented template context variable! #} - {# pageurl implementation: https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html #} - {%- if pageurl %} - {# pageurl implementation wrongly: adds .html for the dirhtml builder's pageurl #} - {# Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 #} - {# Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround #} - {% if builder == 'dirhtml' and pageurl.endswith('.html') %} - {# This expression trims away .html and adds a / #} + {#- + CANONICAL URL + NB! pageurl is currently a non-documented template context variable! + pageurl implementation: https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html + -#} + {%- if pageurl -%} + {#- + pageurl implementation wrongly: adds .html for the dirhtml builder's pageurl + Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 + Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround + -#} + {%- if builder == 'dirhtml' and pageurl.endswith('.html') -%} + {#- This expression trims away .html and adds a / -#} - {% else %} + {%- else -%} - {% endif %} + {%- endif -%} {%- endif -%} {#- JAVASCRIPTS #} From df87a40d0a9c7799231b51ae24399b7499d75ec4 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 11 Jan 2023 16:36:27 +0100 Subject: [PATCH 3/5] Trimmed a bit too many whitespaces --- sphinx_rtd_theme/layout.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index f612bd6be..9b00d0320 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -65,10 +65,10 @@ Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround -#} - {%- if builder == 'dirhtml' and pageurl.endswith('.html') -%} - {#- This expression trims away .html and adds a / -#} + {%- if builder == 'dirhtml' and pageurl.endswith('.html') %} + {#- This expression trims away .html and adds a / #} - {%- else -%} + {%- else %} {%- endif -%} {%- endif -%} From 6beecce44759257ed584f2fdb0357f2aec0ad01a Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 11 Jan 2023 17:18:03 +0100 Subject: [PATCH 4/5] Entirely remove "index.html" from canonical URL if the dirhtml builder was used (retry with GPG signature) --- sphinx_rtd_theme/layout.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index 9b00d0320..af8d59057 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -65,7 +65,10 @@ Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround -#} - {%- if builder == 'dirhtml' and pageurl.endswith('.html') %} + {%- if builder == 'dirhtml' and pageurl.endswith('index.html') %} + {#- This expression trims away index.html entirely #} + + {%- elif builder == 'dirhtml' and pageurl.endswith('.html') %} {#- This expression trims away .html and adds a / #} {%- else %} From a739cc3ea0d91e375c1d7699f958406dcdd67a07 Mon Sep 17 00:00:00 2001 From: Benjamin Balder Bach Date: Wed, 22 Mar 2023 17:37:53 +0100 Subject: [PATCH 5/5] Update sphinx_rtd_theme/layout.html --- sphinx_rtd_theme/layout.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html index af8d59057..3a264fe8c 100644 --- a/sphinx_rtd_theme/layout.html +++ b/sphinx_rtd_theme/layout.html @@ -57,7 +57,9 @@ {#- CANONICAL URL NB! pageurl is currently a non-documented template context variable! - pageurl implementation: https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html + pageurl implementation: + https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html + https://github.com/readthedocs/readthedocs.org/blob/4b2eb75bebfce04390ac3f84d1c57ef7f7126fe8/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl#L151-L156 -#} {%- if pageurl -%} {#-