增加搜索

This commit is contained in:
lanzhihui 2026-01-30 15:12:19 +08:00
parent 81f28e5e9f
commit 9eb218b235
3 changed files with 32 additions and 2 deletions

View File

@ -3,6 +3,8 @@ import { defaultTheme } from '@vuepress/theme-default'
import { defineUserConfig } from 'vuepress' import { defineUserConfig } from 'vuepress'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' import path from 'path'
import { searchPlugin } from '@vuepress/plugin-search'
// import * as path from "path"; // import * as path from "path";
// const path = require("path"); // const path = require("path");
@ -255,6 +257,16 @@ export default defineUserConfig({
} }
} }
}], }],
searchPlugin({
// 可选:自定义最大建议条数
maxSuggestions: 10,
// 可选:设置触发搜索的快捷键(支持多个)
hotKeys: ['s', '/'],
// 可选:自定义搜索索引字段(默认包含 title 和 frontmatter
// getExtraFields: (page) => page.frontmatter.tags,
}),
// registerComponentsPlugin({ // registerComponentsPlugin({
// // 配置项 // // 配置项
// componentsDir: path.resolve(__dirname, '../../', 'components'), // 自动注册全局组件, // componentsDir: path.resolve(__dirname, '../../', 'components'), // 自动注册全局组件,

View File

@ -13,7 +13,7 @@
} }
.vp-sidebar-children { .vp-sidebar-children {
//.vp-sidebar-item{ //.vp-sidebar-item{
.vp-sidebar-children {+ .vp-sidebar-children {
.vp-sidebar-item { .vp-sidebar-item {
//li{ //li{
@ -73,3 +73,20 @@
.vp-navbar-item:hover { .vp-navbar-item:hover {
color: #299764; color: #299764;
} }
.search-box input{
padding-inline: 2rem!important;
}
// 水印样式兼容确保不被侧边栏/导航栏遮挡
.watermark-container {
z-index: 9999 !important;
// 避开VuePress默认主题的层级不遮挡你的侧边栏/导航栏
&:not(.vp-sidebar):not(.vp-navbar) {
pointer-events: none !important;
}
}
// 深色主题适配如果后续开启深色模式保留这段
body.dark .watermark-content::before {
color: #ffffff !important;
opacity: 0.2 !important;
}

View File

@ -21,8 +21,9 @@
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "^6.7.2", "@fortawesome/fontawesome-free": "^6.7.2",
"@vuepress/plugin-medium-zoom": "^2.0.0-rc.86", "@vuepress/plugin-medium-zoom": "^2.0.0-rc.86",
"@vuepress/plugin-search": "^2.0.0-rc.86",
"@vueuse/core": "^13.5.0", "@vueuse/core": "^13.5.0",
"axios": "^1.10.0", "axios": "^1.12.0",
"pinia": "^3.0.3", "pinia": "^3.0.3",
"vue-router": "^4.5.1", "vue-router": "^4.5.1",
"vuepress-plugin-seo": "^0.2.0" "vuepress-plugin-seo": "^0.2.0"