diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index d0743db2..6380f107 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -18,7 +18,9 @@ import { ref, shallowRef, watch, - type Ref + type Ref, + computed, + watchEffect } from 'vue' import type { ModalTranslations } from '../../../../types/local-search' import { pathToFile, withBase } from '../../app/utils' @@ -54,7 +56,7 @@ interface Result { text?: string } -const { localeIndex } = useData() +const { localeIndex, theme } = useData() const searchIndex = computedAsync(async () => markRaw( @@ -80,6 +82,19 @@ const showDetailedList = useLocalStorage( false ) +const disableDetailedView = computed(() => { + return ( + theme.value.search?.provider === 'local' && + theme.value.search.options?.disableDetailedView === true + ) +}) + +watchEffect(() => { + if (disableDetailedView.value) { + showDetailedList.value = false + } +}) + const results: Ref<(SearchResult & Result)[]> = shallowRef([]) const contents = shallowRef(new Map>()) @@ -158,21 +173,16 @@ debouncedWatch( title = title.replace(reg, `$&`) } if (match.includes('titles')) { - titles = titles.flatMap((t) => - t ? [t.replace(reg, `$&`)] : [] - ) + titles = titles + .map((t) => t?.replace(reg, `$&`)) + .filter(Boolean) } if (showDetailedListValue && match.includes('text')) { text = text.replace(reg, `$&`) } } - return { - ...r, - title, - titles, - text - } + return { ...r, title, titles, text } }) contents.value = c @@ -272,9 +282,6 @@ onKeyStroke('Escape', () => { }) // Translations - -const { theme } = useData() - const defaultTranslations: { modal: ModalTranslations } = { modal: { displayDetails: 'Display detailed list', @@ -364,10 +371,9 @@ useEventListener('popstate', (event) => { />