From fb8d0cef6be44334545daef7be30c12b6c9fe7c1 Mon Sep 17 00:00:00 2001 From: "Chloe Lin [SSW]" Date: Wed, 6 Sep 2023 09:04:25 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20People=20Redirection=20(#5?= =?UTF-8?q?28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update redirection * delete unused code --- gatsby-node.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 2eec80ad..2001caad 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -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(), @@ -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 @@ -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); };