Skip to content

Commit 1f47284

Browse files
committed
Adding custom 404 page
Automatically redirects if a page differing only in case is found.
1 parent f48cd02 commit 1f47284

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

404.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
layout: page
3+
title: 404 Page Not Found
4+
---
5+
<script>
6+
var allposts = [];
7+
function redirectToCorrectPage() {
8+
{% for post in site.pages %}
9+
allposts.push("{{ post.url }}");
10+
{% endfor %}
11+
{% for post in site.wikis %}
12+
allposts.push("{{ post.url }}");
13+
{% endfor %}
14+
var url = window.location.pathname;
15+
// strip trailing /
16+
if (url.slice(-1) === "/") {
17+
url = url.slice(0, -1);
18+
}
19+
var allpostsUpperCase = allposts.map(function(value) {
20+
// strip trailing /
21+
if (value.slice(-1) === "/") {
22+
value = value.slice(0, -1);
23+
}
24+
return value.toUpperCase();
25+
});
26+
var i = allpostsUpperCase.indexOf(url.toUpperCase());
27+
if (i != -1) {
28+
console.log(allposts[i]);
29+
window.location = allposts[i];
30+
}
31+
}
32+
window.onload = redirectToCorrectPage;
33+
</script>
34+
<p>Sorry this page does not exist =(</p>

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ defaults:
8383
path: "" # empty string for all files
8484
values:
8585
layout: page
86+

0 commit comments

Comments
 (0)