Переглянути джерело

Add a more descriptive custom 404 error page (#4624)

This helps users find their way back to the documentation.
Hugo Locurcio 4 роки тому
батько
коміт
ad8d17c364
1 змінених файлів з 34 додано та 3 видалено
  1. 34 3
      conf.py

+ 34 - 3
conf.py

@@ -16,7 +16,41 @@ extensions = [
     "godot_descriptions",
     "sphinx_tabs.tabs",
     "sphinx.ext.imgmath",
+    "notfound.extension",
 ]
+
+# Custom 4O4 page HTML template.
+# https://github.com/readthedocs/sphinx-notfound-page
+notfound_context = {
+    "title": "Page not found",
+    "body": """
+        <h1>Page not found</h1>
+        <p>
+            Sorry, we couldn't find that page. It may have been renamed or removed
+            in the version of the documentation you're currently browsing.
+        </p>
+        <p>
+            If you're currently browsing the
+            <em>stable</em> version of the documentation, try browsing the
+            <a href="/en/latest/"><em>latest</em> version of the documentation</a>.
+        </p>
+        <p>
+            Alternatively, use the
+            <a href="#" onclick="$('#rtd-search-form [name=\\'q\\']').focus()">Search docs</a>
+            box on the left or <a href="/">go to the homepage</a>.
+        </p>
+    """,
+}
+
+# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
+on_rtd = os.environ.get("READTHEDOCS", None) == "True"
+
+# Don't add `/en/latest` prefix during local development.
+# This makes it easier to test the custom 404 page by loading `/404.html`
+# on a local web server.
+if not on_rtd:
+    notfound_urls_prefix = ''
+
 templates_path = ["_templates"]
 
 # You can specify multiple suffix as a list of string: ['.rst', '.md']
@@ -93,9 +127,6 @@ highlight_language = "gdscript"
 
 # -- Options for HTML output ----------------------------------------------
 
-# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
-on_rtd = os.environ.get("READTHEDOCS", None) == "True"
-
 import sphinx_rtd_theme
 
 html_theme = "sphinx_rtd_theme"