Skip to content

Commit 4538176

Browse files
authored
Merge pull request #2165 from henryiii/henryiii/feat/404
feat: add a custom 404 page
2 parents caacbe0 + 7a0dd2b commit 4538176

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎requirements.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
furo==2024.8.6
22
sphinx==7.2.6
3-
sphinx-autobuild==2021.3.14
3+
sphinx-autobuild==2024.10.3
44
sphinx-inline-tabs==2023.4.21
55
sphinx-copybutton==0.5.2
66
sphinx-toolbox==3.5.0
77
sphinx-jsonschema==1.19.1
8+
sphinx-notfound-page==1.1.0

‎source/404.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:orphan:
2+
3+
==============
4+
Page not found
5+
==============
6+
7+
The page you requested does not exist. It may have moved or been removed.
8+
Please return to the :doc:`main page <index>`.

‎source/conf.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import pathlib
66
import sys
77

8+
from docutils import nodes
9+
from notfound.utils import replace_uris
10+
811
_ROOT = pathlib.Path(__file__).resolve().parent.parent
912
sys.path.append(os.fspath(_ROOT))
1013

@@ -35,6 +38,7 @@
3538
"sphinx_copybutton",
3639
"sphinx_toolbox.collapse",
3740
"sphinx-jsonschema",
41+
"notfound.extension",
3842
]
3943

4044
nitpicky = True
@@ -250,3 +254,20 @@
250254

251255
copybutton_prompt_text = r">>> |\.\.\. |\$ |> "
252256
copybutton_prompt_is_regexp = True
257+
258+
# -- Options for sphinx-notfound-page --------------------------------------------------
259+
# https://sphinx-notfound-page.readthedocs.io/en/latest/configuration.html
260+
261+
# Local builds are served from the root, RtD seves from /<language>/<version>/
262+
if not RTD_BUILD:
263+
notfound_urls_prefix = "/"
264+
265+
266+
def fix_notfound_links(app, doctree, docname):
267+
# The extension only makes theme links absolute, not links in the page body
268+
if app.builder.format == "html" and docname == app.config.notfound_pagename:
269+
replace_uris(app, doctree, nodes.reference, "refuri")
270+
271+
272+
def setup(app):
273+
app.connect("doctree-resolved", fix_notfound_links)

0 commit comments

Comments
 (0)