From 24cd2ce323fb20dfe1e42d853d33d92f2264a284 Mon Sep 17 00:00:00 2001 From: Colby Ludwig Date: Thu, 22 Jun 2023 16:34:17 -0600 Subject: [PATCH 1/3] refactor how we compose oldIds and newIds for redirects --- script.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 093153b7a..aebe1960c 100644 --- a/script.js +++ b/script.js @@ -336,9 +336,29 @@ document.addEventListener('DOMContentLoaded', function() { } }); +var redirects = { + "360019766773": "360056046054", + "115009518827": "7061327071639", + "115009727208": "8196953752855", + "360021265374": "7448087796631", + "360007324274": "8195739126039", + "115009727668": "7760313735575", + "115009560387": "8185260991127", + "115011697807": "8196925335575", + "360046288634": "8196961124887", + "115009519087": "7447835963159", + "360033659193": "8185260991127", + "115009730468": "8508884808599", + "115009560687": "7447924360855", + "115009730148": "8354601698583", + "360042930793": "7453632138391", + "8420210943767": "7061327071639" +} + // redirects -var oldIds = ["360019766773", "115009518827", "115009727208", "360021265374", "360007324274", "115009727668", "115009560387", "115011697807", "360046288634", "115009519087", "360033659193", "115009730468", "115009560687", "115009730148", "360042930793", "8420210943767"]; -var newIds = ["360056046054", "7061327071639", "8196953752855", "7448087796631", "8195739126039", "7760313735575", "8185260991127", "8196925335575", "8196961124887", "7447835963159", "8185260991127", "8508884808599", "7447924360855", "8354601698583", "7453632138391", "7061327071639"]; +var oldIds = Object.keys(redirects); +var newIds = Object.values(redirects); + for (var i = 0; i < oldIds.length; i++){ if (window.location.href.indexOf(oldIds[i]) > -1) { window.location.href = 'https://help.getjobber.com/hc/en-us/articles/' + newIds[i]; From 1842216bec31033ebe767e40e4dc5db52f6f4f3f Mon Sep 17 00:00:00 2001 From: Colby Ludwig Date: Thu, 22 Jun 2023 17:04:02 -0600 Subject: [PATCH 2/3] Use hash lookup combined with URL manipulation for redirect --- script.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index aebe1960c..be91a2fe8 100644 --- a/script.js +++ b/script.js @@ -359,10 +359,13 @@ var redirects = { var oldIds = Object.keys(redirects); var newIds = Object.values(redirects); -for (var i = 0; i < oldIds.length; i++){ - if (window.location.href.indexOf(oldIds[i]) > -1) { - window.location.href = 'https://help.getjobber.com/hc/en-us/articles/' + newIds[i]; - } +// Split off the current article ID from the rest of the URL to look-up the appropriate redirect. +let [ pageSlug ] = window.location.href.split('/').slice(-1); // e.g.: "14537623807127-How-to-Subscribe" +let [ pageId ] = pageSlug.split('-'); // e.g.: "14537623807127" + +// If we have a redirect for this article ID in the hash, let's perform the redirect. +if (redirects[pageId]) { + window.location.href = `https://help.getjobber.com/hc/en-us/articles/${redirects[pageId]}`; } //billing redirect From fdda3d0e960f29fbbd3e7626fa59789bc8ed5301 Mon Sep 17 00:00:00 2001 From: Colby Ludwig Date: Thu, 22 Jun 2023 17:07:11 -0600 Subject: [PATCH 3/3] improve safety, add short-circuit if pageId is null --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.js b/script.js index be91a2fe8..7dd37d30f 100644 --- a/script.js +++ b/script.js @@ -364,7 +364,7 @@ let [ pageSlug ] = window.location.href.split('/').slice(-1); // e.g.: "145376 let [ pageId ] = pageSlug.split('-'); // e.g.: "14537623807127" // If we have a redirect for this article ID in the hash, let's perform the redirect. -if (redirects[pageId]) { +if (pageId && redirects[pageId]) { window.location.href = `https://help.getjobber.com/hc/en-us/articles/${redirects[pageId]}`; }