Skip to content

Latest commit

 

History

History
71 lines (70 loc) · 2.54 KB

File metadata and controls

71 lines (70 loc) · 2.54 KB
layout
title 404 Redirector
permalink /404.html
<script language="JavaScript"> function doFwd() { var forwardingURL=window.location.href; var domainName = window.location.hostname; var portNumber = window.location.port; var gonnaFwd = false; var newURL = ""; console.log(forwardingURL); {% for item in site.data.redirects %} var redirectVal = {{ item | jsonify }}; if (forwardingURL.indexOf(redirectVal.source) > -1) { console.log("Found via CSV @ ", redirectVal.source, redirectVal.destination); gonnaFwd = true; newURL = forwardingURL.replace(redirectVal.source,redirectVal.destination); } {% endfor %} {% 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.indexOf(aliases[i]) > -1) { 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.indexOf(aliases) > -1) { console.log("Found via Page Aliases on a single-alias page @", forwardingURL.indexOf(aliases[i]), aliases[i]) gonnaFwd = true; newURL = "{{ page.url }}"; } } {% endif %}{% endfor %} {% for item in site.data.docsarchive.docker-compose %} if (forwardingURL.indexOf("/{{ item[0] }}") > -1) { console.log("Found via Docker Compose file for Acrhive") gonnaFwd = true; if(portNumber.length > 0) { // there is a port number in the location; make sure to replace it newURL = forwardingURL.replace(domainName + ":"+ portNumber +"/{{ item[0] }}","{{ page.archiveserver }}:{{ item[1].ports[0] | replace:':4000','' }}"); } else { // no port number in the location; just foward them on newURL = forwardingURL.replace(domainName + "/{{ item[0] }}","{{ page.archiveserver }}:{{ item[1].ports[0] | replace:':4000','' }}"); } newURL = newURL.replace("https:","http:") }{% endfor %} if (gonnaFwd) { console.log("Forwarding to: " + newURL); window.location.replace(newURL); document.write('') } else { window.location.replace("/sorry/#" + forwardingURL); document.write('') } } window.onload = doFwd; </script>