Skip to content

Commit de24b71

Browse files
committed
fix(plugin-search): incorrect local search results
1 parent 1dba45f commit de24b71

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ comment: false
1010
editLink: false
1111
contributors: false
1212
changelog: false
13+
search: false
1314
---
1415

1516
<!-- @include: ../CHANGELOG.md -->

docs/contributing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ readingTime: false
88
editLink: false
99
contributors: false
1010
changelog: false
11+
search: false
1112
---
1213

1314
<!-- @include: ../CONTRIBUTING.md{2-} -->

docs/demos.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ draft: true
1010
externalLinkIcon: false
1111
contributors: false
1212
changelog: false
13+
search: false
1314
docs:
1415
-
1516
name: VuePress Plume

docs/sponsor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ aside: false
77
readingTime: false
88
contributors: false
99
changelog: false
10+
search: false
1011
---
1112

1213
:::important 作者的话

plugins/plugin-search/src/client/components/SearchBox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ debouncedWatch(
120120
// Search
121121
results.value = index
122122
.search(filterTextValue)
123-
.slice(0, 16)
123+
// .slice(0, 16)
124124
.map((r) => {
125125
r.titles = r.titles?.filter(Boolean) || []
126126
return r

plugins/plugin-search/src/client/components/SearchButton.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ const locale = useLocale(toRef(props.locales))
1313
<template>
1414
<button type="button" class="mini-search mini-search-button" :aria-label="locale.placeholder">
1515
<span class="mini-search-button-container">
16-
<svg class="mini-search-search-icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon">
17-
<path
18-
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"
19-
stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"
20-
/>
21-
</svg>
16+
<span class="mini-search-search-icon vpi-mini-search" aria-label="search icon" />
2217
<span class="mini-search-button-placeholder">{{ locale.placeholder }}</span>
2318
</span>
2419
<span class="mini-search-button-keys">
@@ -76,6 +71,10 @@ const locale = useLocale(toRef(props.locales))
7671
align-items: center;
7772
}
7873
74+
.mini-search-button .vpi-mini-search {
75+
--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");
76+
}
77+
7978
.mini-search-button .mini-search-search-icon {
8079
position: relative;
8180
width: 16px;

plugins/plugin-search/src/node/prepareSearchIndex.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ async function writeTemp(app: App) {
118118
}
119119

120120
async function indexFile(page: Page, options: SearchIndexOptions['searchOptions']) {
121+
if (!page.filePath)
122+
return
123+
124+
if (page.frontmatter?.search === false)
125+
return
126+
121127
// get file metadata
122128
const fileId = page.path
123129
const locale = page.pathLocale
@@ -140,7 +146,7 @@ async function indexFile(page: Page, options: SearchIndexOptions['searchOptions'
140146
id,
141147
text,
142148
title: titles.at(-1)!,
143-
titles: titles.slice(0, -1),
149+
titles: [page.frontmatter.title || page.title, ...titles.slice(0, -1)],
144150
}
145151
index.add(item)
146152
cache.push(item)

0 commit comments

Comments
 (0)