Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-search): incorrect local search results #434

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ comment: false
editLink: false
contributors: false
changelog: false
search: false
---

<!-- @include: ../CHANGELOG.md -->
1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ readingTime: false
editLink: false
contributors: false
changelog: false
search: false
---

<!-- @include: ../CONTRIBUTING.md{2-} -->
1 change: 1 addition & 0 deletions docs/demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ draft: true
externalLinkIcon: false
contributors: false
changelog: false
search: false
docs:
-
name: VuePress Plume
Expand Down
1 change: 1 addition & 0 deletions docs/sponsor.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ aside: false
readingTime: false
contributors: false
changelog: false
search: false
---

:::important 作者的话
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-search/src/client/components/SearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ debouncedWatch(
// Search
results.value = index
.search(filterTextValue)
.slice(0, 16)
// .slice(0, 16)
.map((r) => {
r.titles = r.titles?.filter(Boolean) || []
return r
Expand Down
11 changes: 5 additions & 6 deletions plugins/plugin-search/src/client/components/SearchButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ const locale = useLocale(toRef(props.locales))
<template>
<button type="button" class="mini-search mini-search-button" :aria-label="locale.placeholder">
<span class="mini-search-button-container">
<svg class="mini-search-search-icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon">
<path
d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z"
stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"
/>
</svg>
<span class="mini-search-search-icon vpi-mini-search" aria-label="search icon" />
<span class="mini-search-button-placeholder">{{ locale.placeholder }}</span>
</span>
<span class="mini-search-button-keys">
Expand Down Expand Up @@ -76,6 +71,10 @@ const locale = useLocale(toRef(props.locales))
align-items: center;
}

.mini-search-button .vpi-mini-search {
--icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' stroke-width='1.6' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' d='m14.386 14.386 4.088 4.088-4.088-4.088A7.533 7.533 0 1 1 3.733 3.733a7.533 7.533 0 0 1 10.653 10.653z'/%3E%3C/svg%3E");
}

.mini-search-button .mini-search-search-icon {
position: relative;
width: 16px;
Expand Down
8 changes: 7 additions & 1 deletion plugins/plugin-search/src/node/prepareSearchIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ async function writeTemp(app: App) {
}

async function indexFile(page: Page, options: SearchIndexOptions['searchOptions']) {
if (!page.filePath)
return

if (page.frontmatter?.search === false)
return

// get file metadata
const fileId = page.path
const locale = page.pathLocale
Expand All @@ -140,7 +146,7 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions'
id,
text,
title: titles.at(-1)!,
titles: titles.slice(0, -1),
titles: [page.frontmatter.title || page.title, ...titles.slice(0, -1)],
}
index.add(item)
cache.push(item)
Expand Down
Loading