Skip to content

Commit

Permalink
feat(plugin-slimsearch)!: rename autoSuggestions as suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Nov 27, 2024
1 parent a4e0829 commit a7a792a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/search/slimsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/plugins/search/slimsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default defineUserConfig({

:::

### autoSuggestions
### suggestion

- 类型: `boolean`
- 默认值: `false`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'),
Expand Down Expand Up @@ -182,7 +184,7 @@ export default defineComponent({
},
})
: null,
enableAutoSuggestions &&
__SLIMSEARCH_SUGGESTION__ &&
displaySuggestion.value &&
suggestions.value.length
? h(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ 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<string[]>
}

export const useSuggestions = (queries: Ref<string[]>): SuggestionsRef => {
const suggestions = ref<string[]>([])

if (enableAutoSuggestions) {
if (__SLIMSEARCH_SUGGESTION__) {
const searchOptions = useSearchOptions()
const pageData = usePageData()
const routeLocale = useRouteLocale()
Expand Down
2 changes: 0 additions & 2 deletions plugins/search/plugin-slimsearch/src/client/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__
2 changes: 1 addition & 1 deletion plugins/search/plugin-slimsearch/src/node/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface SlimSearchPluginOptions {
*
* @default true
*/
autoSuggestions?: boolean
suggestion?: boolean

/**
* Max stored query history count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit a7a792a

Please sign in to comment.