feat(search): allow force disabling detailed view

pull/2234/head
Divyansh Singh 2 years ago
parent fe1f58b700
commit 40f1d1b6f6

@ -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<string, Map<string, string>>())
@ -158,21 +173,16 @@ debouncedWatch(
title = title.replace(reg, `<mark>$&</mark>`)
}
if (match.includes('titles')) {
titles = titles.flatMap((t) =>
t ? [t.replace(reg, `<mark>$&</mark>`)] : []
)
titles = titles
.map((t) => t?.replace(reg, `<mark>$&</mark>`))
.filter(Boolean)
}
if (showDetailedListValue && match.includes('text')) {
text = text.replace(reg, `<mark>$&</mark>`)
}
}
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) => {
/>
<div class="search-actions">
<button
v-if="!disableDetailedView"
class="toggle-layout-button"
:class="{
'detailed-list': showDetailedList
}"
:class="{ 'detailed-list': showDetailedList }"
:title="$t('modal.displayDetails')"
@click="showDetailedList = !showDetailedList"
>
@ -746,6 +752,7 @@ useEventListener('popstate', (event) => {
background-color: var(--vp-c-highlight-bg);
color: var(--vp-c-highlight-text);
border-radius: 2px;
padding: 0 4px;
}
.excerpt :deep(.vp-code-group) .tabs {

@ -98,7 +98,7 @@
--vp-c-mute-dark: #e3e3e5;
--vp-c-mute-darker: #d7d7d9;
--vp-c-highlight-bg: var(--vp-c-yellow-lighter);
--vp-c-highlight-bg: var(--vp-c-green-lighter);
--vp-c-highlight-text: var(--vp-c-black);
}

@ -293,6 +293,11 @@ export namespace DefaultTheme {
// local search --------------------------------------------------------------
export interface LocalSearchOptions {
/**
* @default false
*/
disableDetailedView?: boolean
translations?: LocalSearchTranslations
locales?: Record<string, Partial<Omit<LocalSearchOptions, 'locales'>>>
}

Loading…
Cancel
Save