feat(theme): 切换为主题内部搜索插件

This commit is contained in:
pengzhanbo 2024-02-20 01:42:00 +08:00
parent 5159c5a434
commit cec3191adc
8 changed files with 167 additions and 35 deletions

View File

@ -30,10 +30,10 @@ export const theme: Theme = themePlume({
},
},
plugins: {
docsearch: {
apiKey: '111',
appId: '111',
indexName: '1234',
},
// docsearch: {
// apiKey: '111',
// appId: '111',
// indexName: '1234',
// },
},
})

View File

@ -14,7 +14,8 @@
{ "path": "./plugin-notes-data/tsconfig.build.json" },
{ "path": "./plugin-page-collection/tsconfig.build.json" },
{ "path": "./plugin-shikiji/tsconfig.build.json" },
{ "path": "./plugin-content-update/tsconfig.build.json" }
{ "path": "./plugin-content-update/tsconfig.build.json" },
{ "path": "./plugin-search/tsconfig.build.json" }
],
"files": []
}

138
pnpm-lock.yaml generated
View File

@ -274,6 +274,39 @@ importers:
specifier: workspace:*
version: link:../plugin-netlify-functions
plugins/plugin-search:
dependencies:
'@vuepress/helper':
specifier: 2.0.0-rc.14
version: 2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7)
'@vueuse/core':
specifier: ^10.7.2
version: 10.7.2(vue@3.4.19)
'@vueuse/integrations':
specifier: ^10.7.2
version: 10.7.2(focus-trap@7.5.4)(vue@3.4.19)
chokidar:
specifier: ^3.6.0
version: 3.6.0
focus-trap:
specifier: ^7.5.4
version: 7.5.4
mark.js:
specifier: ^8.11.1
version: 8.11.1
minisearch:
specifier: ^6.3.0
version: 6.3.0
p-map:
specifier: ^7.0.1
version: 7.0.1
vue:
specifier: ^3.4.19
version: 3.4.19(typescript@5.3.3)
vuepress:
specifier: 2.0.0-rc.7
version: 2.0.0-rc.7(@vuepress/bundler-vite@2.0.0-rc.7)(@vuepress/bundler-webpack@2.0.0-rc.7)(typescript@5.3.3)(vue@3.4.19)
plugins/plugin-shikiji:
dependencies:
'@shikijs/transformers':
@ -321,6 +354,9 @@ importers:
'@vuepress-plume/plugin-notes-data':
specifier: workspace:*
version: link:../plugins/plugin-notes-data
'@vuepress-plume/plugin-search':
specifier: workspace:*
version: link:../plugins/plugin-search
'@vuepress-plume/plugin-shikiji':
specifier: workspace:*
version: link:../plugins/plugin-shikiji
@ -351,9 +387,6 @@ importers:
'@vuepress/plugin-reading-time':
specifier: 2.0.0-rc.14
version: 2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7)
'@vuepress/plugin-search':
specifier: 2.0.0-rc.14
version: 2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7)
'@vuepress/plugin-seo':
specifier: 2.0.0-rc.14
version: 2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7)
@ -3997,7 +4030,7 @@ packages:
'@vue/shared': 3.4.19
estree-walker: 2.0.2
magic-string: 0.30.7
postcss: 8.4.33
postcss: 8.4.35
source-map-js: 1.0.2
/@vue/compiler-ssr@3.4.19:
@ -4328,19 +4361,6 @@ packages:
- typescript
dev: false
/@vuepress/plugin-search@2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7):
resolution: {integrity: sha512-os2Kzj1hePpX5rxmJUSLs783G0EVTuiwFT2gPPBw/3yZbRCXCTnAM6xAVK2vv36Ysa4fgfFETLG4omg1b3rOvQ==}
peerDependencies:
vuepress: 2.0.0-rc.7
dependencies:
chokidar: 3.6.0
vue: 3.4.19(typescript@5.3.3)
vue-router: 4.2.5(vue@3.4.19)
vuepress: 2.0.0-rc.7(@vuepress/bundler-vite@2.0.0-rc.7)(@vuepress/bundler-webpack@2.0.0-rc.7)(typescript@5.3.3)(vue@3.4.19)
transitivePeerDependencies:
- typescript
dev: false
/@vuepress/plugin-seo@2.0.0-rc.14(typescript@5.3.3)(vuepress@2.0.0-rc.7):
resolution: {integrity: sha512-ffYc6XObhei863X/g3BTlJrx+EIWRPmtv/NLp9EDKO72KJX3C+MsDKDJOx54iL3X0DT63F/PMTMg0Y+ZhJ4qCw==}
peerDependencies:
@ -4424,6 +4444,56 @@ packages:
- vue
dev: false
/@vueuse/integrations@10.7.2(focus-trap@7.5.4)(vue@3.4.19):
resolution: {integrity: sha512-+u3RLPFedjASs5EKPc69Ge49WNgqeMfSxFn+qrQTzblPXZg6+EFzhjarS5edj2qAf6xQ93f95TUxRwKStXj/sQ==}
peerDependencies:
async-validator: '*'
axios: '*'
change-case: '*'
drauu: '*'
focus-trap: '*'
fuse.js: '*'
idb-keyval: '*'
jwt-decode: '*'
nprogress: '*'
qrcode: '*'
sortablejs: '*'
universal-cookie: '*'
peerDependenciesMeta:
async-validator:
optional: true
axios:
optional: true
change-case:
optional: true
drauu:
optional: true
focus-trap:
optional: true
fuse.js:
optional: true
idb-keyval:
optional: true
jwt-decode:
optional: true
nprogress:
optional: true
qrcode:
optional: true
sortablejs:
optional: true
universal-cookie:
optional: true
dependencies:
'@vueuse/core': 10.7.2(vue@3.4.19)
'@vueuse/shared': 10.7.2(vue@3.4.19)
focus-trap: 7.5.4
vue-demi: 0.14.6(vue@3.4.19)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
dev: false
/@vueuse/metadata@10.7.2:
resolution: {integrity: sha512-kCWPb4J2KGrwLtn1eJwaJD742u1k5h6v/St5wFe8Quih90+k2a0JP8BS4Zp34XUuJqS2AxFYMb1wjUL8HfhWsQ==}
dev: false
@ -6989,8 +7059,8 @@ packages:
engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0}
dependencies:
is-url: 1.2.4
postcss: 8.4.33
postcss-values-parser: 6.0.2(postcss@8.4.33)
postcss: 8.4.35
postcss-values-parser: 6.0.2(postcss@8.4.35)
dev: false
/detective-sass@5.0.0:
@ -8453,6 +8523,12 @@ packages:
resolution: {integrity: sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==}
dev: false
/focus-trap@7.5.4:
resolution: {integrity: sha512-N7kHdlgsO/v+iD/dMoJKtsSqs5Dz/dXZVebRgJw23LDk+jMi/974zyiOYDziY2JPp8xivq9BmUGwIJMiuSBi7w==}
dependencies:
tabbable: 6.2.0
dev: false
/folder-walker@3.2.0:
resolution: {integrity: sha512-VjAQdSLsl6AkpZNyrQJfO7BXLo4chnStqb055bumZMbRUPpVuPN3a4ktsnRCmrFZjtMlYLkyXiR5rAs4WOpC4Q==}
dependencies:
@ -10765,6 +10841,10 @@ packages:
object-visit: 1.0.1
dev: false
/mark.js@8.11.1:
resolution: {integrity: sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==}
dev: false
/markdown-it-anchor@8.6.7(@types/markdown-it@13.0.7)(markdown-it@14.0.0):
resolution: {integrity: sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==}
peerDependencies:
@ -11095,6 +11175,10 @@ packages:
resolution: {integrity: sha512-ibvbqeslVFur0IAvTxLMvsbtvVcMo6gwvOnj0YZHV7aeDLu091VQRrETT2QuiG9P6aZWRcxeNGJChRKVPCp9VQ==}
dev: false
/minisearch@6.3.0:
resolution: {integrity: sha512-ihFnidEeU8iXzcVHy74dhkxh/dn8Dc08ERl0xwoMMGqp4+LvRSCgicb+zGqWthVokQKvCSxITlh3P08OzdTYCQ==}
dev: false
/minizlib@2.1.2:
resolution: {integrity: sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==}
engines: {node: '>= 8'}
@ -11956,6 +12040,11 @@ packages:
resolution: {integrity: sha512-T8BatKGY+k5rU+Q/GTYgrEf2r4xRMevAN5mtXc2aPc4rS1j3s+vWTaO2Wag94neXuCAUAs8cxBL9EeB5EA6diw==}
engines: {node: '>=16'}
/p-map@7.0.1:
resolution: {integrity: sha512-2wnaR0XL/FDOj+TgpDuRb2KTjLnu3Fma6b1ZUwGY7LcqenMcvP/YFpjpbPKY6WVGsbuJZRuoUz8iPrt8ORnAFw==}
engines: {node: '>=18'}
dev: false
/p-reduce@3.0.0:
resolution: {integrity: sha512-xsrIUgI0Kn6iyDYm9StOpOeK29XM1aboGji26+QEortiFST1hGZaUQOLhtEbqHErPpGW/aSz6allwK2qcptp0Q==}
engines: {node: '>=12'}
@ -12447,7 +12536,7 @@ packages:
/postcss-value-parser@4.2.0:
resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==}
/postcss-values-parser@6.0.2(postcss@8.4.33):
/postcss-values-parser@6.0.2(postcss@8.4.35):
resolution: {integrity: sha512-YLJpK0N1brcNJrs9WatuJFtHaV9q5aAOj+S4DI5S7jgHlRfm0PIbDCAFRYMQD5SHq7Fy6xsDhyutgS0QOAs0qw==}
engines: {node: '>=10'}
peerDependencies:
@ -12455,7 +12544,7 @@ packages:
dependencies:
color-name: 1.1.4
is-url-superb: 4.0.0
postcss: 8.4.33
postcss: 8.4.35
quote-unquote: 1.0.0
dev: false
@ -12466,6 +12555,7 @@ packages:
nanoid: 3.3.7
picocolors: 1.0.0
source-map-js: 1.0.2
dev: true
/postcss@8.4.35:
resolution: {integrity: sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==}
@ -13217,7 +13307,7 @@ packages:
engines: {node: '>=14.0.0'}
hasBin: true
dependencies:
chokidar: 3.5.3
chokidar: 3.6.0
immutable: 4.1.0
source-map-js: 1.0.2
dev: false
@ -14192,6 +14282,10 @@ packages:
picocolors: 1.0.0
dev: false
/tabbable@6.2.0:
resolution: {integrity: sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==}
dev: false
/table@6.8.1:
resolution: {integrity: sha512-Y4X9zqrCftUhMeH2EptSSERdVKt/nEdijTOacGD/97EKjhQ/Qs8RTlEGABSJNNN8lac9kheH+af7yAkEWlgneA==}
engines: {node: '>=10.0.0'}

View File

@ -64,6 +64,7 @@
"@vuepress-plume/plugin-copy-code": "workspace:*",
"@vuepress-plume/plugin-iconify": "workspace:*",
"@vuepress-plume/plugin-notes-data": "workspace:*",
"@vuepress-plume/plugin-search": "workspace:*",
"@vuepress-plume/plugin-shikiji": "workspace:*",
"@vuepress/plugin-active-header-links": "2.0.0-rc.14",
"@vuepress/plugin-container": "2.0.0-rc.12",
@ -74,7 +75,6 @@
"@vuepress/plugin-nprogress": "2.0.0-rc.14",
"@vuepress/plugin-palette": "2.0.0-rc.14",
"@vuepress/plugin-reading-time": "2.0.0-rc.14",
"@vuepress/plugin-search": "2.0.0-rc.14",
"@vuepress/plugin-seo": "2.0.0-rc.14",
"@vuepress/plugin-sitemap": "2.0.0-rc.14",
"@vuepress/plugin-theme-data": "2.0.0-rc.14",

View File

@ -6,7 +6,6 @@ import { gitPlugin } from '@vuepress/plugin-git'
import { mediumZoomPlugin } from '@vuepress/plugin-medium-zoom'
import { nprogressPlugin } from '@vuepress/plugin-nprogress'
import { palettePlugin } from '@vuepress/plugin-palette'
import { searchPlugin } from '@vuepress/plugin-search'
import { themeDataPlugin } from '@vuepress/plugin-theme-data'
import { autoFrontmatterPlugin } from '@vuepress-plume/plugin-auto-frontmatter'
import { baiduTongjiPlugin } from '@vuepress-plume/plugin-baidu-tongji'
@ -22,6 +21,7 @@ import { readingTimePlugin } from '@vuepress/plugin-reading-time'
import { seoPlugin } from '@vuepress/plugin-seo'
import { sitemapPlugin } from '@vuepress/plugin-sitemap'
import { contentUpdatePlugin } from '@vuepress-plume/plugin-content-update'
import { searchPlugin } from '@vuepress-plume/plugin-search'
import type {
PlumeThemeLocaleOptions,
PlumeThemePluginOptions,

View File

@ -1,5 +1,5 @@
import type { DocsearchPluginOptions } from '@vuepress/plugin-docsearch'
import type { SearchPluginOptions } from '@vuepress/plugin-search'
import type { SearchPluginOptions } from '@vuepress-plume/plugin-search'
import type { App } from 'vuepress/core'
import { deepMerge } from '@pengzhanbo/utils'
import { resolvedAppLocales } from './resolveLocaleOptions.js'
@ -50,8 +50,36 @@ const defaultDocsearchLocales: NonNullable<DocsearchPluginOptions['locales']> =
}
const defaultSearchLocales: NonNullable<SearchPluginOptions['locales']> = {
'zh-CN': { placeholder: '搜索' },
'en-US': { placeholder: 'Search' },
'zh-CN': {
placeholder: '搜索文档',
resetButtonTitle: '重置搜索',
backButtonTitle: '关闭',
noResultsText: '无搜索结果:',
footer: {
selectText: '选择',
selectKeyAriaLabel: '输入',
navigateText: '切换',
navigateUpKeyAriaLabel: '向上',
navigateDownKeyAriaLabel: '向下',
closeText: '关闭',
closeKeyAriaLabel: '退出',
},
},
'en-US': {
placeholder: 'Search',
resetButtonTitle: 'Reset search',
backButtonTitle: 'Close search',
noResultsText: 'No results for',
footer: {
selectText: 'to select',
selectKeyAriaLabel: 'enter',
navigateText: 'to navigate',
navigateUpKeyAriaLabel: 'up arrow',
navigateDownKeyAriaLabel: 'down arrow',
closeText: 'to close',
closeKeyAriaLabel: 'escape',
},
},
}
export function resolvedDocsearchOption(app: App, options: DocsearchPluginOptions): DocsearchPluginOptions {

View File

@ -24,7 +24,16 @@ export function plumeTheme({
clientConfigFile: resolve('client/config.js'),
plugins: setupPlugins(app, pluginsOptions, localeOptions),
onInitialized: app => setupPage(app, localeOptions),
extendsPage: page => extendsPageData(app, page as Page<PlumeThemePageData>, localeOptions),
extendsPage: (page) => {
extendsPageData(app, page as Page<PlumeThemePageData>, localeOptions)
page.frontmatter.head ??= []
page.frontmatter.head?.push([
'script',
{ id: 'check-mac-os' },
`document.documentElement.classList.toggle('mac', /Mac|iPhone|iPod|iPad/i.test(navigator.platform))`,
])
},
templateBuildRenderer(template, context) {
template = template
.replace('{{ themeVersion }}', pkg.version || '')

View File

@ -1,5 +1,5 @@
import type { DocsearchOptions } from '@vuepress/plugin-docsearch'
import type { SearchPluginOptions } from '@vuepress/plugin-search'
import type { SearchPluginOptions } from '@vuepress-plume/plugin-search'
import type { AutoFrontmatterOptions } from '@vuepress-plume/plugin-auto-frontmatter'
import type { BaiduTongjiOptions } from '@vuepress-plume/plugin-baidu-tongji'
import type { CanIUsePluginOptions } from '@vuepress-plume/plugin-caniuse'