diff --git a/src/components/404LinkCorrection/index.tsx b/src/components/404LinkCorrection/index.tsx index 9290b88..2fca8f2 100644 --- a/src/components/404LinkCorrection/index.tsx +++ b/src/components/404LinkCorrection/index.tsx @@ -1,6 +1,6 @@ import { WindowLocation } from "@reach/router" import { Link } from "gatsby" -import React, { Fragment } from "react" +import React, { FC, Fragment } from "react" import { FileConnection } from "../../../generated/graphql" @@ -55,12 +55,19 @@ function levenshteinDistance(term1: string, term2: string) { return matrix[term2.length][term1.length] } -export const getPossibleCorrections = ( - basepath: string, - location: WindowLocation, - data: { allFile: FileConnection }, - threshold: number -) => { +interface IPossibleCorrections { + basepath: string + location: WindowLocation + data: { allFile: FileConnection } + threshold?: number +} + +export const PossibleCorrections: FC = ({ + basepath, + location, + data, + threshold = 8, +}) => { // the data prop has the graphql result // we're abstracting it to `linkArray` to just have array of edges matched // must use `.node.absolutePath` on each edge to get each node's absolute link diff --git a/src/pages/archives/404.tsx b/src/pages/archives/404.tsx index 3d31219..7db240a 100644 --- a/src/pages/archives/404.tsx +++ b/src/pages/archives/404.tsx @@ -6,7 +6,7 @@ import { FileConnection } from "../../../generated/graphql" import { ComponentQuery } from "../../../typings" import { SEO } from "../../components/SEO" -import { getPossibleCorrections } from "../../components/404LinkCorrection" +import { PossibleCorrections } from "../../components/404LinkCorrection" export default ({ data }: ComponentQuery<{ allFile: FileConnection }>) => ( @@ -14,7 +14,13 @@ export default ({ data }: ComponentQuery<{ allFile: FileConnection }>) => (

RESOURCE NOT FOUND

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

- {({ location }) => getPossibleCorrections("archives/", location, data, 8)} + {({ location }) => ( + + )}
) diff --git a/src/pages/resources/404.tsx b/src/pages/resources/404.tsx index c1267af..b8fbe40 100644 --- a/src/pages/resources/404.tsx +++ b/src/pages/resources/404.tsx @@ -4,7 +4,7 @@ import React, { Fragment } from "react" import { FileConnection } from "../../../generated/graphql" import { ComponentQuery } from "../../../typings" -import { getPossibleCorrections } from "../../components/404LinkCorrection" +import { PossibleCorrections } from "../../components/404LinkCorrection" import { SEO } from "../../components/SEO" export default ({ data }: ComponentQuery<{ allFile: FileConnection }>) => ( @@ -13,9 +13,13 @@ 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, 8) - } + {({ location }) => ( + + )} )