Created
February 7, 2016 06:21
-
-
Save AmrEldib/81a4660fe00da8f11956 to your computer and use it in GitHub Desktop.
Jekyll 404 page on GitHub Pages to fix case sensitive URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var allposts = []; | |
function redirectToCorrectPage() { | |
{% for post in site.posts %} | |
allposts.push("{{ site.url }}{{ post.url }}"); | |
{% endfor %} | |
var url = window.location.toString(); | |
if (url.slice(-1) === "/") { | |
url = url.slice(0, -1); | |
} | |
var allpostsUpperCase = allposts.map(function(value) { | |
return value.toUpperCase(); | |
}); | |
var i = allpostsUpperCase.indexOf(url.toUpperCase()); | |
if (i != -1) { | |
console.log(allposts[i]); | |
window.location = allposts[i]; | |
} | |
} | |
window.onload = redirectToCorrectPage; |
Add it to your 404.html page. Original blog: https://amreldib.com/blog/FixJekyllCaseSensitiveUrlsOnGitHubPages/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where to load this script?