logo

Grimgrains

[mirror] Plant-based cooking website <https://grimgrains.com/>
commit: 94716b4bf8d7653c0044382007289e98904b1211
parent 82030742b5f36ea6687b028f52daf0761bf0c774
Author: neauoire <aliceffekt@gmail.com>
Date:   Tue, 14 Jan 2020 16:21:31 -0500

Made 404 smarter

Diffstat:

M404.html37+++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/404.html b/404.html @@ -13,17 +13,30 @@ permalink: /404.html <title>GrimGrains</title> </head> <body> - <header> - <a id='logo' href='home.html'><img src='../media/interface/logo.png' alt='Grimgrains'></a> - </header> - <nav> - <ul><li class='home'><a href='home.html'>Home</a></li><li class='about'><a href='about.html'>About</a></li><li class='tools'><a href='tools.html'>Tools</a></li><li class='nutrition'><a href='nutrition.html'>Nutrition</a></li><li class='right'><a href='http://twitter.com/grimgrains' target='_blank'>Twitter</a></li></ul> - </nav> - <main> - <p>The page you were looking for does not exist, if you think this was a mistake, please report the broken link <a href='https://github.com/hundredrabbits/Grimgrains' target='_blank'>here</a>, or go back to the <a href='/site/home.html'>home</a>.</p> - </main> - <footer> - <a href='about.html'>Grimgrains</a> © 2014—2020<br><a href='http://100r.co/' target='_blank'>Hundred Rabbits</a> - </footer> + <p>The page you were looking for does not exist, if you think this was a mistake, please report the broken link <a href='https://github.com/hundredrabbits/Grimgrains' target='_blank'>here</a>, or go back to the <a href='/site/home.html'>home</a>.</p> + + <script> + 'use strict' + + const parts = window.location.pathname.split("/") + const target = parts.slice(-1) + const filename = toFilename(target[0]) + const filepath = `https:/grimgrains.com/site/${filename}.html` + + if(UrlExists(filepath)){ + window.location.replace(filepath) + } + + function UrlExists(url) { + const http = new XMLHttpRequest() + http.open('HEAD', url, false) + http.send() + return http.status!=404 + } + + function toFilename(str){ + return `${str}`.replace('#','').replace(/[\W_]+/g,"_").toLowerCase().trim() + } + </script> </body> </html>