Skip to content

Commit

Permalink
refactor(localSearch): cleanup redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyx1998 committed Dec 23, 2023
1 parent 9ae4c56 commit 719813f
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/node/plugins/localSearchPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ export async function localSearchPlugin(
return siteData?.localeIndex ?? 'root'
}

function getIndexForPath(file: string) {
const locale = getLocaleForPath(file)
return getIndexByLocale(locale)
}

let server: ViteDevServer | undefined

function onIndexUpdated() {
Expand Down Expand Up @@ -216,27 +211,8 @@ export async function localSearchPlugin(

async handleHotUpdate({ file }) {
if (file.endsWith('.md')) {
const fileId = getDocId(file)
if (!fs.existsSync(file)) return
const index = getIndexForPath(file)
const html = await render(file)
const sections =
(await options.miniSearch?.splitIntoSections?.(file, html)) ??
splitPageIntoSections(html)
for await (const section of sections) {
const id = `${fileId}#${section.anchor}`
if (index.has(id)) {
index.discard(id)
}
index.add({
id,
text: section.text,
title: section.titles.at(-1)!,
titles: section.titles.slice(0, -1)
})
}
await indexFile(file)
debug('🔍️ Updated', file)

onIndexUpdated()
}
}
Expand Down

0 comments on commit 719813f

Please sign in to comment.