Skip to content

Commit ae8fe3c

Browse files
committed
canonical url doesn't use page redirect
1 parent cf3a014 commit ae8fe3c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Version 2.3.0
33

44
Unreleased
55

6+
- When getting the canonical URL on Read the Docs, replace the path with
7+
``/en/stable/`` instead of ``/page/``. This can be configured with
8+
``rtd_canonical_path``. :pr:`119`
9+
610

711
Version 2.2.0
812
-------------

src/pallets_sphinx_themes/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def setup(app):
2525
app.add_html_theme(name, path)
2626

2727
app.add_config_value("is_pallets_theme", None, "html")
28+
app.add_config_value("rtd_canonical_path", "/en/stable/", "html")
2829

2930
# Use the sphinx-notfound-page extension to generate a 404 page with valid
3031
# URLs. Only configure it if it's not already configured.
@@ -67,16 +68,16 @@ def setup(app):
6768
@only_pallets_theme()
6869
def find_base_canonical_url(app: Sphinx) -> None:
6970
"""When building on Read the Docs, build the base canonical URL from the
70-
environment variable if it's not given in the config. Read the Docs has a
71-
special `/page/<path>` rule that redirects any path to the current version
72-
of the docs, so that's used as the canonical link.
71+
environment variable if it's not given in the config. Replace the path with
72+
``rtd_canonical_path``, which defaults to ``/en/stable/``.
7373
"""
7474
if app.config.html_baseurl:
7575
return
7676

7777
if "READTHEDOCS_CANONICAL_URL" in os.environ:
7878
parts = urlsplit(os.environ["READTHEDOCS_CANONICAL_URL"])
79-
app.config.html_baseurl = f"{parts.scheme}://{parts.netloc}/page/"
79+
path = app.config.rtd_canonical_path
80+
app.config.html_baseurl = f"{parts.scheme}://{parts.netloc}{path}"
8081

8182

8283
@only_pallets_theme()

0 commit comments

Comments
 (0)