From 73b934ea4fd25a6d4da8f6c81b712712f545b44e Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Tue, 16 Apr 2024 13:17:23 -0700 Subject: [PATCH] adding redirect.js : --- redirect.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 redirect.js diff --git a/redirect.js b/redirect.js new file mode 100644 index 0000000000..e0349d27aa --- /dev/null +++ b/redirect.js @@ -0,0 +1,40 @@ +import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; + +function tryRedirect() { + if (location.host.includes('learn.')) { + return; + } + + let path = location.pathname; + + if (!path.startsWith('/')) { + path = `/${path}`; + } + + location.replace(`https://redis.io/learn${path}`); +} + +export default (function () { + if (!ExecutionEnvironment.canUseDOM) { + return null; + } + + return { + onRouteUpdate({ location }) { + console.log(location); + + tryRedirect(); + setTimeout(tryRedirect, 50); + setTimeout(tryRedirect, 150); + setTimeout(tryRedirect, 250); + setTimeout(tryRedirect, 350); + setTimeout(tryRedirect, 450); + setTimeout(tryRedirect, 550); + setTimeout(tryRedirect, 650); + setTimeout(tryRedirect, 750); + setTimeout(tryRedirect, 850); + setTimeout(tryRedirect, 950); + setTimeout(tryRedirect, 1050); + }, + }; +})();