Skip to content

Commit

Permalink
Entirely remove "index.html" from canonical URL if the dirhtml builde…
Browse files Browse the repository at this point in the history
…r was used
  • Loading branch information
benjaoming committed Jan 11, 2023
1 parent df87a40 commit 2f1b2ec
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 #}
<link rel="canonical" href="{{ (pageurl|e)[:-10] }}" />
{%- elif builder == 'dirhtml' and pageurl.endswith('.html') %}
{#- This expression trims away .html and adds a / #}
<link rel="canonical" href="{{ (pageurl|e)[:-5] }}/" />
{%- else %}
Expand Down

0 comments on commit 2f1b2ec

Please sign in to comment.