方案一:使用algolia
-
首先在该网站发送申请 https://docsearch.algolia.com/apply/ (需要科学上网)
-
注意:
- 您是该网站的所有者
- 你的网站必须是公开的
- 你的网站不能进行商业内容
- 你的网站必须到生产环境
-
填写后等待一段时间会受到邮件
-
此时需要回复邮件,告诉自己就是网站的维护者,并且可以修改代码:例如:
I am the maintainer of the website,I can modify the code
- 等待一段时间后,你会收到包含 AppId 等所需信息的邮件
- 最后你只需要在docs/.vitepress/config.js文件下添加相关信息即可
import { defineConfig } from 'vitepress'
export default defineConfig({
themeConfig: {
search: {
provider: 'algolia',
options: {
appId: '...',
apiKey: '...',
indexName: '...'
}
}
}
})
方案二:本地搜索
VitePress支持使用浏览器内置索引进行模糊全文搜索,,只需在.vitepress/config.js文件中将themeConfig.search.provider选项设置为’local’即可:
import { defineConfig } from 'vitepress'
export default defineConfig({
themeConfig: {
search: {
provider: 'local'
}
}
})