File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 51
51
52
52
{#- CANONICAL URL (deprecated) #}
53
53
{%- if theme_canonical_url and not pageurl %}
54
- < link rel ="canonical " href ="{{ theme_canonical_url }}{{ pagename }}.html "/>
54
+ < link rel ="canonical " href ="{{ theme_canonical_url }}{{ pagename }}{% if builder == 'dirhtml' %}/{% else %} .html{% endif %} "/>
55
55
{%- endif -%}
56
56
57
57
{#- CANONICAL URL #}
58
+ {# NB! pageurl is currently a non-documented template context variable! #}
59
+ {# pageurl implementation: https://www.sphinx-doc.org/en/master/_modules/sphinx/builders/html.html #}
58
60
{%- if pageurl %}
59
- < link rel ="canonical " href ="{{ pageurl|e }} " />
61
+ {# pageurl implementation wrongly: adds .html for the dirhtml builder's pageurl #}
62
+ {# Workaround for: https://github.com/sphinx-doc/sphinx/issues/9730 #}
63
+ {# Once a fix is released in Sphinx, put an upper bound on the Sphinx version for the workaround #}
64
+ {% if builder == 'dirhtml' %}
65
+ < link rel ="canonical " href ="{{ pageurl|e|trim( ".html ") }}" />
66
+ {% else %}
67
+ < link rel ="canonical " href ="{{ pageurl|e }} " />
68
+ {% endif %}
60
69
{%- endif -%}
61
70
62
71
{#- JAVASCRIPTS #}
You can’t perform that action at this time.
0 commit comments