Skip to content

Commit

Permalink
Use READTHEDOCS_CANONICAL_URL for notfound_urls_prefix (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd authored Jan 28, 2025
1 parent 8af414e commit 1fcba8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
5 changes: 2 additions & 3 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ For other use cases, you can customize these configuration options in your ``con

Prefix added to all the URLs generated in the 404 page.

Default: ``'/<language>/<version>/'`` where ``<language>`` is ``READTHEDOCS_LANGUAGE`` environment variable
and ``<version>`` is ``READTHEDOCS_VERSION`` environment variable.
In case these variables are not defined, it defaults to ``/en/latest/``.
Default: The path from the `READTHEDOCS_CANONICAL_URL <https://docs.readthedocs.com/platform/stable/reference/environment-variables.html#envvar-READTHEDOCS_CANONICAL_URL>`__ environment variable.
In case that variables is not defined, it defaults to ``/en/latest/``.

Type: string

Expand Down
21 changes: 7 additions & 14 deletions notfound/extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import html
import os
import warnings
from urllib.parse import urlparse

import docutils.nodes
import sphinx
Expand Down Expand Up @@ -302,22 +303,14 @@ def setup(app):
}

# https://github.com/sphinx-doc/sphinx/blob/master/sphinx/themes/basic/page.html
app.add_config_value('notfound_template', 'page.html', 'html')
app.add_config_value('notfound_context', default_context, 'html')
app.add_config_value('notfound_pagename', '404', 'html')
app.add_config_value("notfound_template", "page.html", "html")
app.add_config_value("notfound_context", default_context, "html")
app.add_config_value("notfound_pagename", "404", "html")

# TODO: get these values from Project's settings
default_language = os.environ.get('READTHEDOCS_LANGUAGE', 'en')
default_version = os.environ.get('READTHEDOCS_VERSION', 'latest')

# This config should replace the previous three
app.add_config_value(
'notfound_urls_prefix',
'/{default_language}/{default_version}/'.format(
default_language=default_language,
default_version=default_version,
),
'html',
"notfound_urls_prefix",
urlparse(os.environ.get("READTHEDOCS_CANONICAL_URL", "/en/latest/")).path,
"html",
types=[str, type(None)],
)

Expand Down

0 comments on commit 1fcba8d

Please sign in to comment.