From cc495938d53cf3b2d7b2bf9ae0c5b11e3330e285 Mon Sep 17 00:00:00 2001
From: Deepak Khatri <lorforlinux@beagleboard.org>
Date: Thu, 26 Sep 2024 03:52:21 +0530
Subject: [PATCH] Add sphinx-notfound-page

---
 404.rst             | 10 ----------
 _templates/404.html | 14 ++++++++++++++
 conf.py             | 12 ++++++++++++
 requirements.txt    |  1 +
 4 files changed, 27 insertions(+), 10 deletions(-)
 delete mode 100644 404.rst
 create mode 100644 _templates/404.html

diff --git a/404.rst b/404.rst
deleted file mode 100644
index 704d231b..00000000
--- a/404.rst
+++ /dev/null
@@ -1,10 +0,0 @@
-:orphan:
-
-.. _not-found:
-
-Document not found
-##################
-
-.. todo::
-
-   We need a 404 document to help people handle broken links (report, find, etc.).
diff --git a/_templates/404.html b/_templates/404.html
new file mode 100644
index 00000000..d9c10c1a
--- /dev/null
+++ b/_templates/404.html
@@ -0,0 +1,14 @@
+{% extends "!layout.html" %}
+
+{% set title = "Page Not Found (404)" %}
+
+{% block title %}{{ title }}{% endblock %}
+
+{% block content %}
+<div class="document">
+    <h1>{{ title }}</h1>
+    <p>Oops! The page you're looking for does not exist.</p>
+    <p>You can return to the <a href="{{ pathto(master_doc) }}">home page</a>.</p>
+    <p>If you believe this is a broken link, please <a href="mailto:your-email@example.com">let us know</a>.</p>
+</div>
+{% endblock %}
diff --git a/conf.py b/conf.py
index d4ef12c4..e842eee1 100644
--- a/conf.py
+++ b/conf.py
@@ -96,6 +96,7 @@ extensions = [
     "sphinx.ext.autodoc",
     "sphinx.ext.autosummary",
     "sphinxext.rediraffe",
+    "notfound.extension",
     "breathe",
     "sphinx_copybutton",
     "sphinxcontrib.youtube",
@@ -143,6 +144,17 @@ for old_folder, new_folder in redirect_folders.items():
             # Add the mapping to rediraffe_redirects
             rediraffe_redirects[str(oldpath)] = str(newpath.relative_to(new_folder_path))
 
+# Specify the 404 template file
+notfound_template = '404.html'
+
+# Set the URLs prefix (adjust if your site is served from a subdirectory)
+notfound_urls_prefix = ''
+
+# Provide additional context variables if needed
+notfound_context = {
+    'title': 'Page Not Found (404)',
+}
+
 #graphviz_output_format = 'svg'
 
 breathe_projects = {"librobotcontrol": "projects/librobotcontrol/docs/xml"}
diff --git a/requirements.txt b/requirements.txt
index efcaf8b8..592ffd72 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -38,3 +38,4 @@ tornado==6.4
 urllib3==2.1.0
 pyyaml>=3.13
 sphinxext-rediraffe>=0.2.7
+sphinx-notfound-page>=1.0.4
-- 
GitLab