-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path404.html
More file actions
129 lines (111 loc) · 5.67 KB
/
404.html
File metadata and controls
129 lines (111 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
permalink: /404.html
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="ai-disclosure" content="ai-assisted">
<title>Page Not Found - austegard.com</title>
<link rel="stylesheet" href="/styles/style.css">
</head>
<body>
<div id="message">
<h1>Oops, we're lost.</h1>
<p>Searching for the page you requested...</p>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
/* Check for short Bluesky URL: /bsky/{postid} -> redirect to bsky.app */
const bskyMatch = window.location.pathname.match(/^\/(bsky|post)\/([a-z2-7]{13})$/);
if (bskyMatch) {
window.location.replace(`https://bsky.app/profile/austegard.com/post/${bskyMatch[2]}`);
return;
}
fetch('/sitemap.xml')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(xmlText => {
/* Parse the XML */
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, 'text/xml');
/* Extract all <loc> elements (URLs) */
const locElements = xmlDoc.getElementsByTagName('loc');
const fileList = [];
/* Convert XML URLs to relative paths */
for (let i = 0; i < locElements.length; i++) {
const url = locElements[i].textContent;
try {
const urlObj = new URL(url);
fileList.push(urlObj.pathname);
} catch (e) {
console.warn('Invalid URL in sitemap:', url);
}
}
const path = window.location.pathname;
const params = window.location.search;
const filename = path.split('/').pop();
if (filename) {
const matches = fileList.filter(file => file.endsWith('/' + filename));
if (matches.length > 0) {
const newPath = matches[0];
const message = document.getElementById('message');
if (message) {
message.innerHTML = `We found it! You are being redirected to <a href="${newPath}${params}">${newPath}</a>...`;
}
setTimeout(() => {
window.location.href = `${newPath}${params}`;
}, 3000);
} else {
/* No matches found - show helpful alternatives */
showNotFoundMessage(filename, path);
}
} else {
/* No filename to search for */
showNotFoundMessage(null, path);
}
})
.catch(error => {
console.error('Error fetching or processing sitemap:', error);
showNotFoundMessage(null, window.location.pathname);
});
function showNotFoundMessage(filename, fullPath) {
const message = document.getElementById('message');
if (!message) return;
let content = '<h1>Page Not Found</h1>';
if (filename) {
const searchTerm = encodeURIComponent(filename.replace(/\.[^.]*$/, '')); /* Remove file extension */
const googleSearchUrl = `https://www.google.com/search?q=site%3Aaustegard.com+${searchTerm}`;
content += `
<p>Sorry, we couldn't find a page matching "<strong>${filename}</strong>" anywhere on this site.</p>
<p>You might want to:</p>
<ul>
<li><a href="${googleSearchUrl}" target="_blank">Search the site for "${filename.replace(/\.[^.]*$/, '')}"</a></li>
<li><a href="/">Go to the home page</a></li>
<li><a href="javascript:history.back()">Go back to the previous page</a></li>
</ul>
`;
} else {
const pathTerm = encodeURIComponent(fullPath.split('/').filter(p => p).pop() || 'content');
const googleSearchUrl = `https://www.google.com/search?q=site%3Aaustegard.com+${pathTerm}`;
content += `
<p>Sorry, we couldn't find the page at "<strong>${fullPath}</strong>".</p>
<p>You might want to:</p>
<ul>
<li><a href="${googleSearchUrl}" target="_blank">Search the site</a></li>
<li><a href="/">Go to the home page</a></li>
<li><a href="javascript:history.back()">Go back to the previous page</a></li>
</ul>
`;
}
message.innerHTML = content;
}
});
</script>
</body>
</html>