diff --git a/requirements.txt b/requirements.txt index 5c710c86bf..b44df79538 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ furo==2024.8.6 sphinx==7.2.6 -sphinx-autobuild==2021.3.14 +sphinx-autobuild==2024.10.3 sphinx-inline-tabs==2023.4.21 sphinx-copybutton==0.5.2 sphinx-toolbox==3.5.0 sphinx-jsonschema==1.19.1 +sphinx-notfound-page==1.1.0 diff --git a/source/404.rst b/source/404.rst new file mode 100644 index 0000000000..77b3d6cfe9 --- /dev/null +++ b/source/404.rst @@ -0,0 +1,8 @@ +:orphan: + +============== +Page not found +============== + +The page you requested does not exist. It may have moved or been removed. +Please return to the :doc:`main page `. diff --git a/source/conf.py b/source/conf.py index 54ab99e81c..f80e6e98be 100644 --- a/source/conf.py +++ b/source/conf.py @@ -5,6 +5,9 @@ import pathlib import sys +from docutils import nodes +from notfound.utils import replace_uris + _ROOT = pathlib.Path(__file__).resolve().parent.parent sys.path.append(os.fspath(_ROOT)) @@ -35,6 +38,7 @@ "sphinx_copybutton", "sphinx_toolbox.collapse", "sphinx-jsonschema", + "notfound.extension", ] nitpicky = True @@ -250,3 +254,20 @@ copybutton_prompt_text = r">>> |\.\.\. |\$ |> " copybutton_prompt_is_regexp = True + +# -- Options for sphinx-notfound-page -------------------------------------------------- +# https://sphinx-notfound-page.readthedocs.io/en/latest/configuration.html + +# Local builds are served from the root, RtD seves from /// +if not RTD_BUILD: + notfound_urls_prefix = "/" + + +def fix_notfound_links(app, doctree, docname): + # The extension only makes theme links absolute, not links in the page body + if app.builder.format == "html" and docname == app.config.notfound_pagename: + replace_uris(app, doctree, nodes.reference, "refuri") + + +def setup(app): + app.connect("doctree-resolved", fix_notfound_links)