Skip to content

Commit

Permalink
Adding custom 404 page
Browse files Browse the repository at this point in the history
Automatically redirects if a page differing only in case is found.
  • Loading branch information
sbliven committed Jul 19, 2016
1 parent f48cd02 commit 1f47284
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 404.html
@@ -0,0 +1,34 @@
---
layout: page
title: 404 Page Not Found
---
<script>
var allposts = [];
function redirectToCorrectPage() {
{% for post in site.pages %}
allposts.push("{{ post.url }}");
{% endfor %}
{% for post in site.wikis %}
allposts.push("{{ post.url }}");
{% endfor %}
var url = window.location.pathname;
// strip trailing /
if (url.slice(-1) === "/") {
url = url.slice(0, -1);
}
var allpostsUpperCase = allposts.map(function(value) {
// strip trailing /
if (value.slice(-1) === "/") {
value = value.slice(0, -1);
}
return value.toUpperCase();
});
var i = allpostsUpperCase.indexOf(url.toUpperCase());
if (i != -1) {
console.log(allposts[i]);
window.location = allposts[i];
}
}
window.onload = redirectToCorrectPage;
</script>
<p>Sorry this page does not exist =(</p>
1 change: 1 addition & 0 deletions _config.yml
Expand Up @@ -83,3 +83,4 @@ defaults:
path: "" # empty string for all files
values:
layout: page

0 comments on commit 1f47284

Please sign in to comment.