mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
99 lines
1.9 KiB
Markdown
99 lines
1.9 KiB
Markdown
---
|
|
title: 内容搜索
|
|
author: pengzhanbo
|
|
createTime: 2024/03/06 09:19:26
|
|
permalink: /config/plugins/search/
|
|
---
|
|
|
|
## 本地搜索
|
|
|
|
### 概述
|
|
|
|
为站点添加本地搜索。
|
|
|
|
关联插件: [@vuepress-plume/plugin-search](https://github.com/pengzhanbo/vuepress-theme-plume/tree/main/plugins/plugin-search)
|
|
|
|
该插件使用 [minisearch](https://github.com/lucaong/minisearch) 进行内容搜索。
|
|
|
|
默认配置:
|
|
|
|
```ts
|
|
import { defineUserConfig } from 'vuepress'
|
|
import { plumeTheme } from 'vuepress-theme-plume'
|
|
|
|
export default defineUserConfig({
|
|
theme: plumeTheme({
|
|
plugins: {
|
|
search: {
|
|
// more options
|
|
}
|
|
}
|
|
})
|
|
})
|
|
```
|
|
|
|
### 配置
|
|
|
|
```ts
|
|
interface SearchOptions {
|
|
/**
|
|
* 本地搜索 国际化
|
|
*/
|
|
locales?: {
|
|
[locale: string]: SearchBoxLocale
|
|
}
|
|
|
|
/**
|
|
* 文章是否可被搜索,默认为 `() => true`
|
|
*/
|
|
isSearchable?: (page: Page) => boolean
|
|
}
|
|
|
|
interface SearchBoxLocale {
|
|
placeholder: string
|
|
buttonText: string
|
|
resetButtonTitle: string
|
|
backButtonTitle: string
|
|
noResultsText: string
|
|
footer: {
|
|
selectText: string
|
|
selectKeyAriaLabel: string
|
|
navigateText: string
|
|
navigateUpKeyAriaLabel: string
|
|
navigateDownKeyAriaLabel: string
|
|
closeText: string
|
|
closeKeyAriaLabel: string
|
|
}
|
|
}
|
|
```
|
|
|
|
## Algolia DocSearch
|
|
|
|
### 概述
|
|
|
|
使用 [Algolia DocSearch](https://docsearch.algolia.com/) 提供支持的网站内容搜索插件
|
|
|
|
关联插件:[@vuepress/plugin-docsearch](https://ecosystem.vuejs.press/zh/plugins/docsearch.html)
|
|
|
|
查看 [Algolia DocSearch 参考](/guide/features/content-search/#algolia-docsearch) 获取更多信息。
|
|
|
|
### 启用
|
|
|
|
```ts
|
|
import { defineUserConfig } from 'vuepress'
|
|
import { plumeTheme } from 'vuepress-theme-plume'
|
|
|
|
export default defineUserConfig({
|
|
theme: plumeTheme({
|
|
plugins: {
|
|
docsearch: {
|
|
appId: 'YOUR_APP_ID',
|
|
apiKey: 'YOUR_API_KEY',
|
|
indexName: 'YOUR_INDEX_NAME',
|
|
// more options
|
|
}
|
|
}
|
|
})
|
|
})
|
|
```
|