diff --git a/docs/plugins/search/slimsearch.md b/docs/plugins/search/slimsearch.md index a70920b073..20fc6a05c4 100644 --- a/docs/plugins/search/slimsearch.md +++ b/docs/plugins/search/slimsearch.md @@ -139,7 +139,7 @@ By default, only headings and excerpt of the page will be indexed along with you ::: -### autoSuggestions +### suggestion - Type: `boolean` - Default: `true` diff --git a/docs/zh/plugins/search/slimsearch.md b/docs/zh/plugins/search/slimsearch.md index 8012da4aff..7b205a223d 100644 --- a/docs/zh/plugins/search/slimsearch.md +++ b/docs/zh/plugins/search/slimsearch.md @@ -137,7 +137,7 @@ export default defineUserConfig({ ::: -### autoSuggestions +### suggestion - 类型: `boolean` - 默认值: `false` diff --git a/plugins/search/plugin-slimsearch/src/client/components/SearchModal.ts b/plugins/search/plugin-slimsearch/src/client/components/SearchModal.ts index 81a37e066b..05d38d3592 100644 --- a/plugins/search/plugin-slimsearch/src/client/components/SearchModal.ts +++ b/plugins/search/plugin-slimsearch/src/client/components/SearchModal.ts @@ -25,7 +25,7 @@ import { useArrayCycle, useSuggestions, } from '../composables/index.js' -import { enableAutoSuggestions, locales, options } from '../define.js' +import { locales, options } from '../define.js' import { useSearchOptions } from '../helpers/index.js' import { CLOSE_ICON } from '../icons/index.js' import SearchKeyHints from './SearchKeyHints.js' @@ -34,6 +34,8 @@ import { SearchIcon } from './icons.js' import '../styles/search-modal.css' +declare const __SLIMSEARCH_SUGGESTION__: boolean + const SearchResult = defineAsyncComponent({ loader: () => import(/* webpackChunkName: "slimsearch-result" */ './SearchResult.js'), @@ -182,7 +184,7 @@ export default defineComponent({ }, }) : null, - enableAutoSuggestions && + __SLIMSEARCH_SUGGESTION__ && displaySuggestion.value && suggestions.value.length ? h( diff --git a/plugins/search/plugin-slimsearch/src/client/composables/useSuggestions.ts b/plugins/search/plugin-slimsearch/src/client/composables/useSuggestions.ts index 17ebad7af7..17042e4a96 100644 --- a/plugins/search/plugin-slimsearch/src/client/composables/useSuggestions.ts +++ b/plugins/search/plugin-slimsearch/src/client/composables/useSuggestions.ts @@ -3,10 +3,11 @@ import type { Ref } from 'vue' import { onMounted, onUnmounted, ref, watch } from 'vue' import { usePageData, useRouteLocale } from 'vuepress/client' -import { enableAutoSuggestions } from '../define.js' import { useSearchOptions } from '../helpers/index.js' import { createSearchWorker } from '../utils/index.js' +declare const __SLIMSEARCH_SUGGESTION__: boolean + export interface SuggestionsRef { suggestions: Ref } @@ -14,7 +15,7 @@ export interface SuggestionsRef { export const useSuggestions = (queries: Ref): SuggestionsRef => { const suggestions = ref([]) - if (enableAutoSuggestions) { + if (__SLIMSEARCH_SUGGESTION__) { const searchOptions = useSearchOptions() const pageData = usePageData() const routeLocale = useRouteLocale() diff --git a/plugins/search/plugin-slimsearch/src/client/define.ts b/plugins/search/plugin-slimsearch/src/client/define.ts index 2556bbdb1f..02becd69d2 100644 --- a/plugins/search/plugin-slimsearch/src/client/define.ts +++ b/plugins/search/plugin-slimsearch/src/client/define.ts @@ -9,7 +9,6 @@ type SlimSearchClientCustomFiledConfig = Record< SlimSearchCustomFieldFormatter > -declare const __SLIMSEARCH_AUTO_SUGGESTIONS__: boolean declare const __SLIMSEARCH_CUSTOM_FIELDS__: SlimSearchClientCustomFiledConfig declare const __SLIMSEARCH_OPTIONS__: { searchDelay: number @@ -22,7 +21,6 @@ declare const __SLIMSEARCH_OPTIONS__: { declare const __SLIMSEARCH_LOCALES__: SlimSearchLocaleConfig export const customFieldConfig = __SLIMSEARCH_CUSTOM_FIELDS__ -export const enableAutoSuggestions = __SLIMSEARCH_AUTO_SUGGESTIONS__ export const options = __SLIMSEARCH_OPTIONS__ export const hotKeysConfig = options.hotKeys export const locales = __SLIMSEARCH_LOCALES__ diff --git a/plugins/search/plugin-slimsearch/src/node/options.ts b/plugins/search/plugin-slimsearch/src/node/options.ts index 0d433423b3..22dd38f1cb 100644 --- a/plugins/search/plugin-slimsearch/src/node/options.ts +++ b/plugins/search/plugin-slimsearch/src/node/options.ts @@ -73,7 +73,7 @@ export interface SlimSearchPluginOptions { * * @default true */ - autoSuggestions?: boolean + suggestion?: boolean /** * Max stored query history count diff --git a/plugins/search/plugin-slimsearch/src/node/slimsearchPlugin.ts b/plugins/search/plugin-slimsearch/src/node/slimsearchPlugin.ts index 4a192450ba..a25b625a72 100644 --- a/plugins/search/plugin-slimsearch/src/node/slimsearchPlugin.ts +++ b/plugins/search/plugin-slimsearch/src/node/slimsearchPlugin.ts @@ -34,7 +34,7 @@ export const slimsearchPlugin = name: PLUGIN_NAME, define: { - __SLIMSEARCH_AUTO_SUGGESTIONS__: options.autoSuggestions ?? true, + __SLIMSEARCH_SUGGESTION__: options.suggestion ?? true, __SLIMSEARCH_CUSTOM_FIELDS__: fromEntries( options.customFields ?.map(({ formatter }, index) =>