Skip to content

Commit

Permalink
fix: lazy init fuzzy page search client
Browse files Browse the repository at this point in the history
Maybe fixes #14
  • Loading branch information
harlan-zw committed Aug 29, 2023
1 parent dd03595 commit 646e6ff
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/runtime/plugin/search.nitro.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Fuse from 'fuse.js'
import { defineNitroPlugin } from 'nitropack/dist/runtime/plugin'

export default defineNitroPlugin(async (nitro) => {
const pages = await $fetch('/api/__link_checker__/links') as string[]
nitro._linkCheckerPageSearch = new Fuse(pages, {
threshold: 0.5,
})
export default defineNitroPlugin((nitro) => {
setTimeout(() => {
$fetch('/api/__link_checker__/links').then((pages: string[]) => {
// @ts-expect-error context hack
nitro._linkCheckerPageSearch = new Fuse(pages, {
threshold: 0.5,
})
})
}, 200)
})

0 comments on commit 646e6ff

Please sign in to comment.