mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 09:15:58 +02:00
feat(404): add threshold parameter, number of characters a link can be editted to be correct
This commit is contained in:
committed by
Jean-Philippe Sirois
parent
713f9c1629
commit
56df4abeb6
@@ -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
|
||||
|
||||
@@ -13,7 +13,7 @@ export default ({ data }: ComponentQuery<{ allFile: FileConnection }>) => (
|
||||
<h1>RESOURCE NOT FOUND</h1>
|
||||
<p>You just hit a route that doesn't exist... the sadness.</p>
|
||||
<Location>
|
||||
{({ location }) => getPossibleCorrections("resources", location, data)}
|
||||
{({ location }) => getPossibleCorrections("resources", location, data, 8)}
|
||||
</Location>
|
||||
</Fragment>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user