Skip to content

Commit 33f9b55

Browse files
fix: init flexsearch plugin: remove unsupported getExtraFields
1 parent c0b632c commit 33f9b55

File tree

3 files changed

+4
-39
lines changed

3 files changed

+4
-39
lines changed

docs/plugins/flexsearch.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,6 @@ export default {
124124
}
125125
```
126126

127-
### getExtraFields
128-
129-
- Type: `(page: Page) => string[]`
130-
131-
- Default: `() => []`
132-
133-
- Details:
134-
135-
A function to add extra fields to the search index of a page.
136-
137-
By default, this plugin will use page title and headers as the search index. This option could help you to add more searchable fields.
138-
139-
- Example:
140-
141-
```ts
142-
export default {
143-
plugins: [
144-
searchPlugin({
145-
// allow searching the `tags` frontmatter
146-
getExtraFields: (page) => page.frontmatter.tags ?? [],
147-
}),
148-
],
149-
}
150-
```
151-
152127
## Styles
153128

154129
You can customize the style of the search box via CSS variables:

plugins/plugin-flexsearch/src/node/flexsearchPlugin.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,13 @@ export interface SearchPluginOptions {
4040
* A function to determine whether a page should be included in the search index
4141
*/
4242
isSearchable?: (page: Page) => boolean
43-
44-
/**
45-
* A function to add extra fields to the search index of a page
46-
*/
47-
getExtraFields?: (page: Page) => string[]
4843
}
4944

5045
export const flexsearchPlugin = ({
5146
locales = {},
5247
hotKeys = ['s', '/'],
5348
maxSuggestions = 5,
5449
isSearchable = () => true,
55-
getExtraFields = () => [],
5650
}: SearchPluginOptions = {}): Plugin => ({
5751
name: '@vuepress/plugin-flexsearch',
5852

@@ -65,25 +59,23 @@ export const flexsearchPlugin = ({
6559
},
6660

6761
onPrepared: async (app) => {
68-
await prepareSearchIndex({ app, isSearchable, getExtraFields })
62+
await prepareSearchIndex({ app, isSearchable })
6963
},
7064

7165
onWatched: (app, watchers) => {
7266
// here we only watch the page data files
73-
// if the extra fields generated by `getExtraFields` are not included
74-
// in the page data, the changes may not be watched
7567
const searchIndexWatcher = chokidar.watch('pages/**/*.js', {
7668
cwd: app.dir.temp(),
7769
ignoreInitial: true,
7870
})
7971
searchIndexWatcher.on('add', () => {
80-
prepareSearchIndex({ app, isSearchable, getExtraFields })
72+
prepareSearchIndex({ app, isSearchable })
8173
})
8274
searchIndexWatcher.on('change', () => {
83-
prepareSearchIndex({ app, isSearchable, getExtraFields })
75+
prepareSearchIndex({ app, isSearchable })
8476
})
8577
searchIndexWatcher.on('unlink', () => {
86-
prepareSearchIndex({ app, isSearchable, getExtraFields })
78+
prepareSearchIndex({ app, isSearchable })
8779
})
8880
watchers.push(searchIndexWatcher)
8981
},

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ const prepContent = (html: string): string => {
3131
export const prepareSearchIndex = async ({
3232
app,
3333
isSearchable,
34-
getExtraFields,
3534
}: {
3635
app: App
3736
isSearchable: Required<SearchPluginOptions>['isSearchable']
38-
getExtraFields: Required<SearchPluginOptions>['getExtraFields']
3937
}): Promise<string> => {
4038
// generate search index
4139
const pages = app.pages.filter(isSearchable)

0 commit comments

Comments
 (0)