aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/Error/path.ts4
-rw-r--r--src/routes/+error.svelte2
2 files changed, 5 insertions, 1 deletions
diff --git a/src/lib/Error/path.ts b/src/lib/Error/path.ts
index 75c035d7..1e36268c 100644
--- a/src/lib/Error/path.ts
+++ b/src/lib/Error/path.ts
@@ -1,6 +1,10 @@
import levenshtein from 'fast-levenshtein';
export const closest = (path: string, suggestions: string[]) => {
+ const partialMatches = suggestions.filter((suggestion) => suggestion.includes(path));
+
+ if (partialMatches.length) return partialMatches[0];
+
const suggestionsWithDistance = suggestions.map((suggestion) => {
const distance = levenshtein.get(path, suggestion);
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
index 03e5bfc0..cf0dc34e 100644
--- a/src/routes/+error.svelte
+++ b/src/routes/+error.svelte
@@ -3,7 +3,7 @@
import { closest } from '$lib/Error/path';
import Popup from '$lib/Popup.svelte';
- $: suggestion = closest($page.url.pathname, [
+ $: suggestion = closest($page.url.pathname.replace('/', ''), [
'birthdays',
'completed',
'schedule',