Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Redirect old URLs to /alumni page #686

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
bradystroud marked this conversation as resolved.
Show resolved Hide resolved
}

// 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({
bradystroud marked this conversation as resolved.
Show resolved Hide resolved
fromPath: originalPath,
toPath: `/${person.path}`, // Redirects to the alumni page
isPermanent: true,
});
return;
}

Expand Down