Skip to content

Commit

Permalink
✨ Redirect old URLs to /alumni page (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradystroud authored Sep 25, 2024
1 parent 1a8f31b commit 971674b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down

0 comments on commit 971674b

Please sign in to comment.