diff --git a/plugins/plugin-search/src/client/components/SearchBox.vue b/plugins/plugin-search/src/client/components/SearchBox.vue index 3e541a79..495c0f5f 100644 --- a/plugins/plugin-search/src/client/components/SearchBox.vue +++ b/plugins/plugin-search/src/client/components/SearchBox.vue @@ -101,7 +101,7 @@ const mark = computedAsync(async () => { return markRaw(new Mark(resultsEl.value)) }, null) -const cache = new LRUCache>(16) // 16 files +const cache = new LRUCache>(64) // 64 files debouncedWatch( () => [searchIndex.value, filterText.value] as const, @@ -121,12 +121,8 @@ debouncedWatch( // Search results.value = index - .search(filterTextValue) - // .slice(0, 16) - .map((r) => { - r.titles = r.titles?.filter(Boolean) || [] - return r - }) as (SearchResult & Result)[] + .search(filterTextValue) as (SearchResult & Result)[] + // .slice(0, 16) enableNoResults.value = true const terms = new Set() @@ -696,6 +692,7 @@ svg { padding: 0 2px; color: var(--vp-mini-search-highlight-text); background-color: var(--vp-mini-search-highlight-bg); + background-image: none; border-radius: 2px; } diff --git a/plugins/plugin-search/src/node/prepareSearchIndex.ts b/plugins/plugin-search/src/node/prepareSearchIndex.ts index d5965982..cab1ae7a 100644 --- a/plugins/plugin-search/src/node/prepareSearchIndex.ts +++ b/plugins/plugin-search/src/node/prepareSearchIndex.ts @@ -131,7 +131,8 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions' const index = getIndexByLocale(locale, options) const cache = getIndexCache(fileId) // retrieve file and split into "sections" - const html = page.contentRendered + const html = `

${page.frontmatter.title || page.title}

+${page.contentRendered}` const sections = splitPageIntoSections(html) if (cache && cache.length) @@ -147,7 +148,7 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions' id, text, title: titles.at(-1)!, - titles: [page.frontmatter.title || page.title, ...titles.slice(0, -1)], + titles: titles.slice(0, -1), } index.add(item) cache.push(item) @@ -157,7 +158,7 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions' // eslint-disable-next-line regexp/no-super-linear-backtracking const headingRegex = /(.*?<\/a>)<\/h\1>/gi // eslint-disable-next-line regexp/no-super-linear-backtracking -const headingContentRegex = /(.*?)<\/a>/i +const headingContentRegex = /(.*?)<\/span><\/a>/i /** * Splits HTML into sections based on headings @@ -175,13 +176,16 @@ function* splitPageIntoSections(html: string) { const content = result[i + 2] if (!title || !content) continue - const titles = parentTitles.slice(0, level) - titles[level] = title - yield { anchor, titles, text: getSearchableText(content) } + if (level === 0) parentTitles = [title] else parentTitles[level] = title + + let titles = parentTitles.slice(0, level) + titles[level] = title + titles = titles.filter(Boolean) + yield { anchor, titles, text: getSearchableText(content) } } }