diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 9fb78d35..42fe55d1 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -53,7 +53,7 @@ export default defineConfig({ indexName: 'vitepress' }, - // offlineSearch: true, + // localSearch: true, carbonAds: { code: 'CEBDT27Y', diff --git a/docs/reference/default-theme-search.md b/docs/reference/default-theme-search.md index fe704c4b..8b43db3d 100644 --- a/docs/reference/default-theme-search.md +++ b/docs/reference/default-theme-search.md @@ -1,15 +1,15 @@ # Search -## Offline Search +## Local Search -VitePress supports fuzzy full-text search using a in-browser index thanks to [minisearch](https://github.com/lucaong/minisearch/). You can enable it in your `.vitepress/config.ts` with the `offlineSearch` theme config: +VitePress supports fuzzy full-text search using a in-browser index thanks to [minisearch](https://github.com/lucaong/minisearch/). You can enable it in your `.vitepress/config.ts` with the `localSearch` theme config: ```ts import { defineConfig } from 'vitepress' export default defineConfig({ themeConfig: { - offlineSearch: true + localSearch: true } }) ``` @@ -20,7 +20,7 @@ Example result: Alternatively, you can use [Algolia DocSearch](#algolia-search) or some community plugins like or . -### i18n {#offline-search-i18n} +### i18n {#local-search-i18n} You can use a config like this to use multilingual search: @@ -29,7 +29,7 @@ import { defineConfig } from 'vitepress' export default defineConfig({ themeConfig: { - offlineSearch: { + localSearch: { locales: { zh: { translations: { diff --git a/src/client/shim.d.ts b/src/client/shim.d.ts index 4fad996e..ba980db7 100644 --- a/src/client/shim.d.ts +++ b/src/client/shim.d.ts @@ -21,7 +21,7 @@ declare module '@theme/index' { export default theme } -declare module '@offlineSearchIndex' { +declare module '@localSearchIndex' { const data: Record Promise<{ default: string }>> export default data } diff --git a/src/client/theme-default/components/VPOfflineSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue similarity index 96% rename from src/client/theme-default/components/VPOfflineSearchBox.vue rename to src/client/theme-default/components/VPLocalSearchBox.vue index 2a8e1714..755d9fc7 100644 --- a/src/client/theme-default/components/VPOfflineSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -3,10 +3,10 @@ import { markRaw, nextTick, onMounted, ref, shallowRef, watch, type Ref, createA import { useRouter } from 'vitepress' import { onKeyStroke, useSessionStorage, debouncedWatch, useLocalStorage, useEventListener, computedAsync } from '@vueuse/core' import MiniSearch, { type SearchResult } from 'minisearch' -import offlineSearchIndex from '@offlineSearchIndex' +import localSearchIndex from '@localSearchIndex' import { useData } from '../composables/data' import { createTranslate } from '../support/translation' -import type { ModalTranslations } from '../../../../types/offline-search' +import type { ModalTranslations } from '../../../../types/local-search' import { pathToFile, withBase } from '../../app/utils.js' defineProps<{ @@ -21,11 +21,11 @@ const el = ref() /* Search */ -const searchIndexData = shallowRef(offlineSearchIndex) +const searchIndexData = shallowRef(localSearchIndex) // hmr if (import.meta.hot) { - import.meta.hot.accept('/@offlineSearchIndex', (m) => { + import.meta.hot.accept('/@localSearchIndex', (m) => { if (m) { searchIndexData.value = m.default } @@ -50,9 +50,9 @@ const searchIndex = computedAsync(async () => markRaw(MiniSearch.loadJSON = shallowRef([]) @@ -226,7 +226,7 @@ const router = useRouter() onKeyStroke('Enter', () => { const selectedPackage = results.value[selectedIndex.value] if (selectedPackage) { - router.go(selectedPackage.id) + router.go(withBase(selectedPackage.id)) emit('close') } }) @@ -255,7 +255,7 @@ const defaultTranslations: { modal: ModalTranslations } = { } } -const $t = createTranslate(theme.value.offlineSearch, defaultTranslations) +const $t = createTranslate(theme.value.localSearch, defaultTranslations) // Back @@ -272,7 +272,7 @@ useEventListener('popstate', event => {