-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5993529
commit 6ad2695
Showing
29 changed files
with
1,043 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# search | ||
|
||
<NpmBadge package="@vuepress/plugin-flexsearch" /> | ||
|
||
Provide local search to your documentation site. | ||
|
||
Unlike the `search` plugin, the `flexsearch` plugin uses the [FlexSearch](https://github.com/nextapps-de/flexsearch) library and pre-indexes both the title and the content of the pages. | ||
|
||
::: tip | ||
Default theme will add search box to the navbar once you configure this plugin correctly. | ||
|
||
This plugin may not be used directly in other themes, so you'd better refer to the documentation of your theme for more details. | ||
::: | ||
|
||
## Usage | ||
|
||
```bash | ||
npm i -D @vuepress/plugin-flexsearch@next | ||
``` | ||
|
||
```ts | ||
import { searchPlugin } from '@vuepress/plugin-flexsearch' | ||
|
||
export default { | ||
plugins: [ | ||
searchPlugin({ | ||
// options | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## Local Search Index | ||
|
||
This plugin will generate search index from your pages locally, and load the search index file when users enter your site. In other words, this is a lightweight built-in search which does not require any external requests. | ||
|
||
While this plugin should be able to handle more pages than the `search` plugin, as it is using an index, the limit of how many pages it can support has not been tested yet. Please refer to [FlexSearch](https://github.com/nextapps-de/flexsearch) benchmarks for more detailed info. | ||
|
||
Another alternative to this plugin is to use a more professional solution - [docsearch](./docsearch.md). | ||
|
||
## Options | ||
|
||
### locales | ||
|
||
- Type: `Record<string, { placeholder: string }>` | ||
|
||
- Details: | ||
|
||
The text of the search box in different locales. | ||
|
||
If this option is not specified, it will fallback to default text. | ||
|
||
- Example: | ||
|
||
```ts | ||
export default { | ||
plugins: [ | ||
searchPlugin({ | ||
locales: { | ||
'/': { | ||
placeholder: 'Search', | ||
}, | ||
'/zh/': { | ||
placeholder: '搜索', | ||
}, | ||
}, | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
- Also see: | ||
- [Guide > I18n](https://vuejs.press/guide/i18n.html) | ||
|
||
### hotKeys | ||
|
||
- Type: `(string | HotKeyOptions)[]` | ||
|
||
@[code ts](@vuepress/plugin-flexsearch/src/shared/hotKey.ts) | ||
|
||
- Default: `['s', '/']` | ||
|
||
- Details: | ||
|
||
Specify the [event.key](http://keycode.info/) of the hotkeys. | ||
|
||
When hotkeys are pressed, the search box input will be focused. | ||
|
||
Set to an empty array to disable hotkeys. | ||
|
||
### maxSuggestions | ||
|
||
- Type: `number` | ||
|
||
- Default: `5` | ||
|
||
- Details: | ||
|
||
Specify the maximum number of search results. | ||
|
||
### isSearchable | ||
|
||
- Type: `(page: Page) => boolean` | ||
|
||
- Default: `() => true` | ||
|
||
- Details: | ||
|
||
A function to determine whether a page should be included in the search index. | ||
|
||
- Return `true` to include the page. | ||
- Return `false` to exclude the page. | ||
|
||
- Example: | ||
|
||
```ts | ||
export default { | ||
plugins: [ | ||
searchPlugin({ | ||
// exclude the homepage | ||
isSearchable: (page) => page.path !== '/', | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
### getExtraFields | ||
|
||
- Type: `(page: Page) => string[]` | ||
|
||
- Default: `() => []` | ||
|
||
- Details: | ||
|
||
A function to add extra fields to the search index of a page. | ||
|
||
By default, this plugin will use page title and headers as the search index. This option could help you to add more searchable fields. | ||
|
||
- Example: | ||
|
||
```ts | ||
export default { | ||
plugins: [ | ||
searchPlugin({ | ||
// allow searching the `tags` frontmatter | ||
getExtraFields: (page) => page.frontmatter.tags ?? [], | ||
}), | ||
], | ||
} | ||
``` | ||
|
||
## Styles | ||
|
||
You can customize the style of the search box via CSS variables: | ||
|
||
@[code css](@vuepress/plugin-flexsearch/src/client/styles/vars.css) | ||
|
||
## Components | ||
|
||
### SearchBox | ||
|
||
- Details: | ||
|
||
This plugin will register a `<SearchBox />` component globally, and you can use it without any props. | ||
|
||
Put this component to where you want to place the search box. For example, default theme puts this component to the end of the navbar. | ||
|
||
::: tip | ||
This component is mainly used for theme development. You don't need to use it directly in most cases. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@vuepress/plugin-flexsearch", | ||
"version": "2.0.0-rc.18", | ||
"description": "VuePress plugin - built-in search using flexsearch", | ||
"keywords": [ | ||
"vuepress-plugin", | ||
"vuepress", | ||
"plugin", | ||
"search" | ||
], | ||
"homepage": "https://ecosystem.vuejs.press/plugins/flexsearch.html", | ||
"bugs": { | ||
"url": "https://github.com/vuepress/ecosystem/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuepress/ecosystem.git", | ||
"directory": "plugins/plugin-flexsearch" | ||
}, | ||
"license": "MIT", | ||
"author": "svalaskevicius", | ||
"type": "module", | ||
"exports": { | ||
".": "./lib/node/index.js", | ||
"./client": "./lib/client/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./lib/node/index.js", | ||
"types": "./lib/node/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "tsc -b tsconfig.build.json", | ||
"clean": "rimraf --glob ./lib ./*.tsbuildinfo", | ||
"copy": "cpx \"src/**/*.{d.ts,svg}\" lib", | ||
"style": "sass src:lib --no-source-map" | ||
}, | ||
"dependencies": { | ||
"chokidar": "^3.6.0", | ||
"flexsearch": "^0.6", | ||
"he": "^1.2.0", | ||
"vue": "^3.4.21" | ||
}, | ||
"peerDependencies": { | ||
"vuepress": "2.0.0-rc.8" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Oops, something went wrong.