From 40f1d1b6f6f2f6c43fd0d9bcf4b6bc1174ce4831 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sun, 16 Apr 2023 14:59:36 +0530 Subject: [PATCH] feat(search): allow force disabling detailed view --- .../components/VPLocalSearchBox.vue | 41 +++++++++++-------- src/client/theme-default/styles/vars.css | 2 +- types/default-theme.d.ts | 5 +++ 3 files changed, 30 insertions(+), 18 deletions(-) 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) => { />