Add 404 and sitemap handler (#1181)

This commit is contained in:
Leendert de Borst
2025-09-07 10:52:40 +02:00
parent a14066c43f
commit ee2fd9f9ae
5 changed files with 129 additions and 0 deletions

68
docs/404.html Normal file
View File

@@ -0,0 +1,68 @@
---
layout: default
title: 404 - Page not found
permalink: /404.html
nav_exclude: true
search_exclude: true
---
<style>
.error-404 {
text-align: center;
padding: 4rem 2rem;
}
.error-404 h1 {
font-size: 6rem;
color: #f49541;
margin-bottom: 1rem;
}
.error-404 h2 {
font-size: 2rem;
margin-bottom: 1rem;
color: #f8f9fa;
}
.error-404 p {
font-size: 1.2rem;
margin-bottom: 2rem;
color: #d1d5db;
}
.error-404 .btn {
display: inline-block;
padding: 0.75rem 1.5rem;
background-color: #d68338;
color: white;
text-decoration: none;
border-radius: 4px;
transition: background-color 0.2s;
}
.error-404 .btn:hover {
background-color: #f49541;
}
.error-404 .links {
margin-top: 2rem;
}
.error-404 .links a {
margin: 0 1rem;
color: #f49541;
text-decoration: underline;
}
.error-404 .links a:hover {
color: #ffd5a8;
}
</style>
<div class="error-404">
<h1>404</h1>
<h2>Page Not Found</h2>
<p>The page you're looking for doesn't exist or may have been moved.</p>
<p>This could happen if the documentation structure has been reorganized or the page has been renamed.</p>
<a href="{{ '/' | relative_url }}" class="btn">Go to Home</a>
<div class="links">
<p>Or try these helpful links:</p>
<a href="{{ '/installation/' | relative_url }}">Installation Guide</a>
<a href="{{ '/browser-extension/' | relative_url }}">Browser Extension</a>
<a href="{{ '/mobile-app/' | relative_url }}">Mobile App</a>
</div>
</div>

View File

@@ -6,3 +6,7 @@ gem "just-the-docs"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
gem "github-pages", group: :jekyll_plugins
group :jekyll_plugins do
gem "jekyll-sitemap"
end

View File

@@ -284,6 +284,7 @@ PLATFORMS
DEPENDENCIES
github-pages
jekyll-sitemap
just-the-docs
BUNDLED WITH

View File

@@ -41,3 +41,15 @@ callouts:
important:
title: Important
color: yellow
# 404 page
defaults:
- scope:
path: "404.html"
values:
sitemap: false
# Sitemap settings
url: "https://docs.aliasvault.net"
plugins:
- jekyll-sitemap

View File

@@ -0,0 +1,44 @@
require 'webrick'
module Jekyll
class FourOhFourPage < StaticFile
def write(dest)
true
end
end
class FourOhFourGenerator < Generator
priority :low
def generate(site)
site.static_files << FourOhFourPage.new(site, site.dest, '/', '404.html')
end
end
end
# Override WEBrick to serve 404.html for missing files
if defined?(WEBrick)
module WEBrick
class HTTPServlet::FileHandler
alias_method :do_GET_original, :do_GET
def do_GET(req, res)
do_GET_original(req, res)
rescue HTTPStatus::NotFound => ex
return_404_page(req, res)
rescue => ex
raise ex
end
def return_404_page(req, res)
path = File.join(@config[:DocumentRoot], '404.html')
if File.exist?(path)
res.body = File.read(path)
res['content-type'] = 'text/html'
else
raise HTTPStatus::NotFound
end
end
end
end
end