From 5eb6ec26da099bc6c8bd18377e87dcd557d2bf1d Mon Sep 17 00:00:00 2001 From: "Brady Stroud [SSW]" Date: Wed, 25 Sep 2024 21:25:09 +0930 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=20Redirect=20old=20URLs=20to=20/al?= =?UTF-8?q?umni=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatsby-node.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gatsby-node.js b/gatsby-node.js index 2bab1d5..833886d 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -481,6 +481,11 @@ exports.createPages = async function ({ actions, graphql }) { }, }); + function getLastSegment(url) { + let segments = url.split('/'); + return segments[segments.length - 1]; + } + // if person has a nickname (even if they are alumni), create a redirect from it if (person.nicknamePath && person.path !== person.nicknamePath) { const nicknamePath = person.nicknamePath.replace( @@ -499,6 +504,12 @@ exports.createPages = async function ({ actions, graphql }) { } if (person.path.includes('alumni')) { + var originalPath = getLastSegment(person.path); // Gets the path, removing the /alumni/ prefix + actions.createRedirect({ + fromPath: originalPath, + toPath: `/${person.path}`, // Redirects to the alumni page + isPermanent: true, + }); return; }