内容搜索
约 524 字
本地搜索
概述
为站点添加本地搜索。
功能说明请参考 搜索功能
关联插件: @vuepress-plume/plugin-search
默认配置:
.vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
search: {
provider: 'local',
// more options...
},
})
})关于配置入口的优先级说明,请参考 插件配置入口。
配置
interface SearchOptions {
/**
* 搜索提供者,本地搜索固定为 'local'(必填)
*/
provider: 'local'
/**
* 本地搜索 国际化
*/
locales?: {
[locale: string]: SearchBoxLocale
}
/**
* 文章是否可被搜索,默认为 `() => true`
*
* 注意:被加密的文章(`encrypt.rules` 命中或页面 `password`)始终不会被索引,
* 搜索索引是公开下发的静态资源,收录加密文章会使其内容泄漏。
*/
isSearchable?: (page: Page) => boolean
/**
* 是否禁用会话存储中的搜索查询持久化
*
* @default false
*/
disableQueryPersistence?: boolean
/**
* MiniSearch 配置
*/
miniSearch?: {
/**
* MiniSearch 实例选项
* @see https://lucaong.github.io/minisearch/modules/_minisearch_.html#options
*/
options?: Pick<MiniSearchOptions, 'extractField' | 'tokenize' | 'processTerm'>
/**
* MiniSearch 搜索选项
* @see https://lucaong.github.io/minisearch/modules/_minisearch_.html#searchoptions-1
*/
searchOptions?: MiniSearchOptions['searchOptions']
}
}
interface SearchBoxLocale {
placeholder: string
buttonText: string
resetButtonTitle: string
backButtonTitle: string
noResultsText: string
/**
* 搜索索引缺失或加载失败时显示的文本
*/
searchIndexErrorText?: string
/**
* 禁用 JavaScript 时显示的降级提示文本
*
* 该文本渲染在 `<noscript>` 中,需为不含 HTML 转义字符的纯文本
*/
noscriptText?: string
footer: {
selectText: string
selectKeyAriaLabel: string
navigateText: string
navigateUpKeyAriaLabel: string
navigateDownKeyAriaLabel: string
closeText: string
closeKeyAriaLabel: string
}
}禁用
将 search 设置为 false 可完全关闭搜索,此时导航栏不再渲染搜索框:
.vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
search: false,
}),
})Algolia DocSearch
概述
使用 Algolia DocSearch 提供支持的网站内容搜索插件
关联插件:@vuepress/plugin-docsearch
查看 Algolia DocSearch 参考 获取更多信息。
启用
.vuepress/config.ts
import { defineUserConfig } from 'vuepress'
import { plumeTheme } from 'vuepress-theme-plume'
export default defineUserConfig({
theme: plumeTheme({
search: {
provider: 'algolia',
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_API_KEY',
indexName: 'YOUR_INDEX_NAME',Object literal may only specify known properties, and 'indexName' does not exist in type 'DocSearchOptions'. // more options
},
})
})关于配置入口的优先级说明,请参考 插件配置入口。
贡献者
更新日志
2026/10/13 15:56
查看所有更新日志
e4dae-docs: improve docs (#1071)于3c257-feat(plugin-search): support search index shard loading (#1055)于9667f-fix(theme): prevent encrypted pages from being indexed by search (#1046)于1d04d-feat: add builtin auto-import-components (#932)于0daf2-docs: improve docs (#929)于aede6-fix(theme): twoslash comment error (#881)于4d236-feat(theme)!: add collections support (#704)于74dfa-docs: enable twoslash for code block于0fd6c-refactor(theme): improve types and flat config (#524)于0c53b-docs: improve docs (#332)于
