主题
搜索CtrlK
主题
原项目使用了 vitepress-plugin-search
插件,该插件存在 HTML 结构问题:
<div> cannot be child of <p>, according to HTML specifications
这个警告出现在 node_modules/vitepress-plugin-search/dist/Search.vue
文件的第230行,违反了 HTML 规范。
我们创建了一个自定义的搜索组件来替换有问题的第三方插件:
.vitepress/theme/components/CustomSearch.vue
.vitepress/theme/utils/search.js
.vitepress/theme/index.js
.vitepress/config.mjs
和 package.json
vitepress-plugin-search
插件配置和依赖Ctrl+K
.vitepress/
├── theme/
│ ├── components/
│ │ └── CustomSearch.vue # 自定义搜索组件
│ ├── utils/
│ │ └── search.js # 搜索工具类
│ ├── index.js # 主题配置(已更新)
│ └── style.css
└── config.mjs # VitePress配置(已更新)
在 .vitepress/theme/utils/search.js
文件的 initializeSearch()
函数中添加新的文档:
searchIndex.addDocument(
'document-id',
'文档标题',
'文档内容描述',
'/guide/document-path'
)
在 .vitepress/theme/components/CustomSearch.vue
文件的 <style>
部分修改样式。
可以在 SearchIndex
类中添加更多搜索算法和功能。