Skip to content

Latest commit

 

History

History
86 lines (79 loc) · 2.49 KB

404.md

File metadata and controls

86 lines (79 loc) · 2.49 KB
layout title permalink
404 Redirector
/404.html
<script language="JavaScript"> var forwardingURL=window.location.pathname; if (forwardingURL.charAt(forwardingURL.length - 1) != "/") forwardingURL += "/"; var gonnaFwd = false; var newURL = ""; var baseURL = ""; var archive = false; console.log(forwardingURL); // .MD EXTENSION CHECK if (forwardingURL.indexOf(".md") > -1) { gonnaFwd = true; newURL = forwardingURL.replace(".md",""); } else { // DOCS ARCHIVE CHECK {% for item in site.data.docsarchive.docker-compose %} if (forwardingURL == "/{{ item[0] }}/") { console.log("Found via Docker Compose file for Acrhive") gonnaFwd = true; archive = true; // make it so redirects cascade; first, use the base URL, then append path baseURL = "{{ site.url }}"; newURL = forwardingURL; }{% endfor %} if (archive==false) { // CSV CHECK {% for item in site.data.redirects %} var redirectVal = {{ item | jsonify }}; if (forwardingURL == redirectVal.source) { console.log("Found via CSV @ ", redirectVal.source, redirectVal.destination); gonnaFwd = true; newURL = forwardingURL.replace(redirectVal.source,redirectVal.destination); } {% endfor %} // PAGE ALIASES CHECK {% for page in site.pages %}{% if page.aliases %} var aliases = {{ page.aliases | jsonify }}; if( Object.prototype.toString.call( aliases ) === '[object Array]' ) { // aliases is an array, therefore, there are multiple aliases for (i=0; i< aliases.length; i++) { if (forwardingURL == aliases[i]) { console.log("Found via Page Aliases on a multi-alias page @", "{{ page.url }}", aliases[i]) gonnaFwd = true; newURL = "{{ page.url }}"; } } } else { // only one alias for this page. if (forwardingURL == aliases) { console.log("Found via Page Aliases on a single-alias page @", forwardingURL.indexOf(aliases[i]), aliases[i]) gonnaFwd = true; newURL = "{{ page.url }}"; } } {% endif %}{% endfor %} } // end of check for .md } // end of check for archive if (gonnaFwd) { newURL = baseURL + newURL; console.log("Forwarding to: " + newURL); window.location.replace(newURL); window.location.href = newURL; document.write('') } else { window.location.replace("/sorry/#" + forwardingURL); window.location.href = "/sorry/#" + forwardingURL; document.write('') } </script>