Skip to content

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

docs/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ Changelog
55
master
66
======
77

8+
Other Changes
9+
-------------
10+
11+
* The ``canonical_url`` option was deprecated in favor of Sphinx's ``html_baseurl``.
12+
813
New Features
914
------------
1015

1116
* New theme option to enable anonymous ip addresses when using Google Analytics (#889)
1217

18+
1319
v0.5.0
1420
======
1521

docs/configuring.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ For example:
1313
.. code:: python
1414
1515
html_theme_options = {
16-
'canonical_url': '',
1716
'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard
1817
'analytics_anonymize_ip': False,
1918
'logo_only': False,
@@ -119,6 +118,12 @@ Miscellaneous options
119118
documentation is available through. The URL points to the root path of the
120119
documentation and requires a trailing slash.
121120

121+
.. deprecated:: 0.6.0
122+
123+
Use :confval:`sphinx:html_baseurl` instead.
124+
125+
.. _canonical URL: https://en.wikipedia.org/wiki/Canonical_link_element
126+
122127
.. confval:: display_version
123128

124129
:type: boolean
@@ -165,10 +170,7 @@ Miscellaneous options
165170
:default: ``#2980B9``
166171

167172
Changes the background of the search area in the navigation bar. The value
168-
can be anything valid in a CSS `background` property.
169-
170-
.. _canonical URL: https://en.wikipedia.org/wiki/Canonical_link_element
171-
173+
can be anything valid in a CSS `background` property.
172174

173175
File-wide metadata
174176
==================

sphinx_rtd_theme/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,47 @@
66

77
from os import path
88

9-
import sphinx
9+
from sphinx import version_info
10+
from sphinx.locale import _
11+
12+
try:
13+
# Avaliable from Sphinx 1.6
14+
from sphinx.util.logging import getLogger
15+
except ImportError:
16+
from logging import getLogger
1017

1118

1219
__version__ = '0.5.0'
1320
__version_full__ = __version__
1421

22+
logger = getLogger(__name__)
23+
1524

1625
def get_html_theme_path():
1726
"""Return list of HTML theme paths."""
1827
cur_dir = path.abspath(path.dirname(path.dirname(__file__)))
1928
return cur_dir
2029

2130

31+
def config_initiated(app, config):
32+
theme_options = config.html_theme_options or {}
33+
if theme_options.get('canonical_url'):
34+
logger.warning(
35+
_('The canonical_url option is deprecated, use the html_baseurl option from Sphinx instead.')
36+
)
37+
38+
2239
# See http://www.sphinx-doc.org/en/stable/theming.html#distribute-your-theme-as-a-python-package
2340
def setup(app):
24-
if sphinx.version_info >= (1, 6, 0):
41+
if version_info >= (1, 6, 0):
2542
# Register the theme that can be referenced without adding a theme path
2643
app.add_html_theme('sphinx_rtd_theme', path.abspath(path.dirname(__file__)))
2744

28-
if sphinx.version_info >= (1, 8, 0):
45+
if version_info >= (1, 8, 0):
2946
# Add Sphinx message catalog for newer versions of Sphinx
3047
# See http://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_message_catalog
3148
rtd_locale_path = path.join(path.abspath(path.dirname(__file__)), 'locale')
3249
app.add_message_catalog('sphinx', rtd_locale_path)
50+
app.connect('config-inited', config_initiated)
3351

3452
return {'parallel_read_safe': True, 'parallel_write_safe': True}

sphinx_rtd_theme/layout.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,17 @@
3838
{% if favicon %}
3939
<link rel="shortcut icon" href="{{ pathto('_static/' + favicon, 1) }}"/>
4040
{% endif %}
41-
{# CANONICAL URL #}
42-
{% if theme_canonical_url %}
41+
42+
{# CANONICAL URL (deprecated) #}
43+
{% if theme_canonical_url and not pageurl %}
4344
<link rel="canonical" href="{{ theme_canonical_url }}{{ pagename }}.html"/>
4445
{% endif %}
4546

47+
{# CANONICAL URL #}
48+
{%- if pageurl %}
49+
<link rel="canonical" href="{{ pageurl|e }}" />
50+
{%- endif %}
51+
4652
{# JAVASCRIPTS #}
4753
{%- block scripts %}
4854
<!--[if lt IE 9]>

0 commit comments

Comments
 (0)