From 56df4abeb6cae27593397df002071e10c4518df2 Mon Sep 17 00:00:00 2001 From: Khinshan Khan Date: Sat, 25 Jan 2020 15:40:40 -0500 Subject: [PATCH] feat(404): add threshold parameter, number of characters a link can be editted to be correct --- src/components/404LinkCorrection/index.tsx | 5 +++-- src/pages/resources/404.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/404LinkCorrection/index.tsx b/src/components/404LinkCorrection/index.tsx index 7d3339e..f54a637 100644 --- a/src/components/404LinkCorrection/index.tsx +++ b/src/components/404LinkCorrection/index.tsx @@ -58,7 +58,8 @@ function levenshteinDistance(term1: string, term2: string) { export const getPossibleCorrections = ( basepath: string, location: WindowLocation, - data: { allFile: FileConnection } + data: { allFile: FileConnection }, + threshold: number ) => { // the data prop has the graphql result // we're abstracting it to `linkArray` to just have array of edges matched @@ -82,7 +83,7 @@ export const getPossibleCorrections = ( levenshteinDistance( search.toLowerCase(), value.node!.relativePath!.toLowerCase() - ) < 8 + ) < threshold ) // helpful message if no matches found diff --git a/src/pages/resources/404.tsx b/src/pages/resources/404.tsx index bd3990f..ebb1cd0 100644 --- a/src/pages/resources/404.tsx +++ b/src/pages/resources/404.tsx @@ -13,7 +13,7 @@ export default ({ data }: ComponentQuery<{ allFile: FileConnection }>) => (

RESOURCE NOT FOUND

You just hit a route that doesn't exist... the sadness.

- {({ location }) => getPossibleCorrections("resources", location, data)} + {({ location }) => getPossibleCorrections("resources", location, data, 8)} )