|
9 | 9 | import type { TextInputChangeEvent } from '@nick-mazuk/ui-svelte/src/form/inputs/text-input' |
10 | 10 | import Spacer from '@nick-mazuk/ui-svelte/src/utilities/spacer/spacer.svelte' |
11 | 11 | import Script from '$lib/components/script.svelte' |
12 | | - import scriptData from '$lib/lib/script-data.json' |
13 | | - import type { ScriptData } from '$lib/types/script-data' |
| 12 | + import scriptData from '../lib/lib/script-data.json' |
| 13 | + import type { ScriptData } from '../lib/types/script-data' |
14 | 14 | import Container from '@nick-mazuk/ui-svelte/src/utilities/container/container.svelte' |
15 | 15 | import { formatNumber } from '@nick-mazuk/lib/esm/number-styling' |
16 | 16 | import Button from '@nick-mazuk/ui-svelte/src/elements/button/button.svelte' |
17 | 17 | import Seo from '@nick-mazuk/ui-svelte/src/utilities/seo/seo.svelte' |
18 | 18 |
|
19 | 19 | import luaLogo from '$lib/assets/images/lua-logo.gif' |
20 | 20 |
|
21 | | - let scripts: ScriptData[] = scriptData |
| 21 | + const scripts: ScriptData[] = scriptData |
22 | 22 | const search = new Search('name') |
23 | 23 | search.addIndex('name') |
24 | 24 | search.addIndex('shortDescription') |
|
27 | 27 |
|
28 | 28 | const allIndexes = new Set<number>() |
29 | 29 |
|
30 | | - const normalizeName = (name: string) => name.normalize('NFD').replace(/[\u0300-\u036f]/g, '') |
| 30 | + const normalizeName = (name: string) => name.normalize('NFD').replace(/[\u0300-\u036F]/gu, '') |
31 | 31 | scripts.forEach((script, index) => { |
32 | 32 | search.addDocument({ |
33 | 33 | ...script, |
|
59 | 59 | if (currentSearch in searchCache) { |
60 | 60 | displayedDocuments = searchCache[currentSearch] |
61 | 61 | } else { |
62 | | - const results: ScriptData[] = search.search(currentSearch) |
| 62 | + const results = search.search(currentSearch) as (ScriptData & { index: number })[] |
63 | 63 | const sortedResults = results.sort((a, b) => a.name.localeCompare(b.name)) |
64 | 64 | displayedDocuments = { |
65 | | - items: new Set(results.map((script: ScriptData) => script.index)), |
| 65 | + items: new Set(results.map((script) => script.index)), |
66 | 66 | first: sortedResults[0]?.index ?? -1, |
67 | 67 | last: sortedResults[sortedResults.length - 1]?.index ?? -1, |
68 | 68 | } |
69 | 69 | searchCache[currentSearch] = displayedDocuments |
70 | 70 | } |
71 | 71 | } |
72 | | - $: if (typeof window !== 'undefined') |
| 72 | + $: if (typeof window !== 'undefined') { |
73 | 73 | window.history.replaceState( |
74 | 74 | null, |
75 | 75 | '', |
76 | 76 | searchValue ? `/scripts?search=${searchValue}` : '/scripts' |
77 | 77 | ) |
| 78 | + } |
78 | 79 | </script> |
79 | 80 |
|
80 | 81 | <Seo |
|
0 commit comments