From 8ab5ec17375cf147cb5a5966b5c054157c4656eb Mon Sep 17 00:00:00 2001 From: Khinshan Khan Date: Sun, 26 Jan 2020 10:04:15 -0500 Subject: [PATCH] fix(404): 404 for collections to properly get their layout applied --- gatsby-node.js | 4 ++-- src/components/404LinkCorrection/index.tsx | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index f53c260..8874cbd 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -174,9 +174,9 @@ exports.onCreatePage = async ({ page, actions }) => { const oldPage = { ...page } page.matchPath = `/archives/*` deletePage(oldPage) - } else { - page.context.layout = resolveLayout(page.path) } + + page.context.layout = resolveLayout(page.path) createPage(page) } diff --git a/src/components/404LinkCorrection/index.tsx b/src/components/404LinkCorrection/index.tsx index 2d00eb0..9290b88 100644 --- a/src/components/404LinkCorrection/index.tsx +++ b/src/components/404LinkCorrection/index.tsx @@ -78,13 +78,14 @@ export const getPossibleCorrections = ( // filter based on distance // levenshtein distance of x means how 'off' it was - const displayArray = linkArray.filter( - value => + const displayArray = linkArray.filter(value => { + return ( levenshteinDistance( search.toLowerCase(), value.node!.relativePath!.toLowerCase() ) < threshold - ) + ) + }) // helpful message if no matches found const found = displayArray.length === 0 ? "Oops, nothing similar found." : ""