Skip to content

Commit

Permalink
🐛 Fix People Redirection (#528)
Browse files Browse the repository at this point in the history
* update redirection

* delete unused code
  • Loading branch information
Aibono1225 authored Sep 6, 2023
1 parent da00197 commit fb8d0ce
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ exports.createPages = async function ({ actions, graphql }) {
const nickname = crmData ? crmData.nickname : null;

const prefix = isCurrent ? '' : alumniPrefix.replace('/', '') + '/';

return {
slug: node.parent.name,
path: prefix + node.parent.name.toLowerCase(),
Expand Down Expand Up @@ -453,11 +452,22 @@ exports.onPostBuild = async ({ store, pathPrefix }) => {
(page) =>
page.path !== alumniPrefix + '/' && page.path.startsWith(alumniPrefix)
)
.map((page) => {
return {
fromPath: pathPrefix + '/' + page.path.replace(alumniPrefix + '/', ''),
toPath: pathPrefix + page.path,
};
.flatMap((page) => {
const fromPathWithSlash =
pathPrefix + '/' + page.path.replace(alumniPrefix + '/', '');
const toPathWithSlash = pathPrefix + page.path;
const fromPathWithoutSlash = fromPathWithSlash.replace(/\/$/, '');

return [
{
fromPath: fromPathWithSlash,
toPath: toPathWithSlash,
},
{
fromPath: fromPathWithoutSlash,
toPath: toPathWithSlash,
},
];
});

//Fetch existing URL redirects for previous Nicknames
Expand Down Expand Up @@ -486,5 +496,6 @@ exports.onPostBuild = async ({ store, pathPrefix }) => {
const allRewritesUnique = [
...new Map(allRewrites.map((item) => [item.fromPath, item])).values(),
];

await createRewriteMap.writeRewriteMapsFile(pluginData, allRewritesUnique);
};

0 comments on commit fb8d0ce

Please sign in to comment.