Skip to content

Commit b9726b8

Browse files
committed
Sphinx: use html_baseurl for setting the canonical URL
Fixes readthedocs/readthedocs-sphinx-ext#83
1 parent 8118908 commit b9726b8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ context = {
120120
'commit': {% if project.repo_type == 'git' %}'{{ commit|slice:"8" }}'{% else %}'{{ commit }}'{% endif %},
121121
}
122122

123+
# For sphinx >=1.8 we can use html_baseurl to set the canonical URL.
124+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl
125+
if version_info >= (1, 8):
126+
if not globals().get('html_baseurl'):
127+
html_baseurl = context['canonical_url']
128+
context['canonical_url'] = None
129+
130+
123131
{# Provide block for extending context data from child template #}
124132
{% block extra_context %}{% endblock %}
125133

0 commit comments

Comments
 (0)