fix(search): ready event is not fired on mac

pull/2248/head
Divyansh Singh 1 year ago
parent 67f1f912d9
commit e37e5cb45a

@ -20,10 +20,6 @@ Example result:
![screenshot of the search modal](/search.png)
::: info
On dev server, the search index is generated on the fly and contains only the recently edited files. So don't worry if you don't see any results when you first open the search modal. It should work fine in production.
:::
Alternatively, you can use [Algolia DocSearch](#algolia-search) or some community plugins like <https://www.npmjs.com/package/vitepress-plugin-search> or <https://www.npmjs.com/package/vitepress-plugin-pagefind>.
### i18n {#local-search-i18n}

@ -72,7 +72,7 @@ export async function localSearchPlugin(
let server: ViteDevServer | undefined
async function onIndexUpdated() {
function onIndexUpdated() {
if (server) {
server.moduleGraph.onFileChange(LOCAL_SEARCH_INDEX_REQUEST_PATH)
// HMR
@ -146,22 +146,10 @@ export async function localSearchPlugin(
return {
name: 'vitepress:local-search',
configureServer(_server) {
async configureServer(_server) {
server = _server
server.watcher.on('ready', async () => {
const watched = server!.watcher.getWatched()
const files = Object.keys(watched).reduce((acc, dir) => {
acc.push(
...watched[dir]
.map((file) => dir + '/' + file)
.filter((file) => file.endsWith('.md'))
)
return acc
}, [] as string[])
await indexAllFiles(files)
onIndexUpdated()
})
await scanForBuild()
onIndexUpdated()
},
resolveId(id) {
@ -203,7 +191,7 @@ export async function localSearchPlugin(
}
const index = getIndexForPath(ctx.file)
const sections = splitPageIntoSections(
await md.render(await fs.readFile(ctx.file, 'utf-8'))
md.render(await fs.readFile(ctx.file, 'utf-8'))
)
for (const section of sections) {
const id = `${fileId}#${section.anchor}`

Loading…
Cancel
Save