Skip to content

Commit b9e8d79

Browse files
authored
Deprecate canonical_url in favor of html_baseurl (#178)
Rely on html_baseurl for the canonical url instead. The canonical url is already set in the basic theme https://github.com/sphinx-doc/sphinx/blob/4e9d1553968653df6699b20afc22b73eb3280185/sphinx/themes/basic/layout.html#L130-L132 That takes into account pages using the dirhtml builder instead of always adding the `html` extension. This was introduced in sphinx 1.8.
1 parent 848e718 commit b9e8d79

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

alabaster/layout.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
{% if theme_touch_icon %}
77
<link rel="apple-touch-icon" href="{{ pathto('_static/' ~ theme_touch_icon, 1) }}" />
88
{% endif %}
9-
{% if theme_canonical_url %}
9+
10+
{# Deprecated in favor of html_baseurl (pageurl). This is already set in the basic theme #}
11+
{% if theme_canonical_url and not pageurl %}
1012
<link rel="canonical" href="{{ theme_canonical_url }}{{ pagename }}.html" />
1113
{% endif %}
1214
{% endblock %}

docs/customization.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ Settings related to text display, logo, etc.
7171

7272
* ``body_text_align``: Which CSS ``text-align`` value to use for body text
7373
(if there is any.)
74-
* ``canonical_url``: If set, is used as the base URL (set before the relative
74+
* ``canonical_url``: **Deprecated**, please use the html_baseurl_ Sphinx option instead.
75+
If set, is used as the base URL (set before the relative
7576
path/pagename) for a ``<link rel="canonical">`` `canonical URL
7677
<https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls>`_ header tag.
7778

7879
.. note:: This value must end with a trailing slash.
7980

81+
.. _html_baseurl: https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl
82+
8083
* ``description``: Text blurb about your project, to appear under the logo.
8184
* ``description_font_style``: Which CSS ``font-style`` to use for description
8285
text.

0 commit comments

Comments
 (0)