1
1
<script setup lang="ts">
2
2
import colors from ' tailwindcss/colors'
3
+ // import { debounce } from 'perfect-debounce'
3
4
import type { NuxtError } from ' #app'
4
5
5
6
const props = defineProps <{
@@ -11,7 +12,19 @@ const appConfig = useAppConfig()
11
12
const colorMode = useColorMode ()
12
13
13
14
const { data : navigation } = await useAsyncData (' navigation' , () => queryCollectionNavigation (' content' ))
14
- const { data : files } = await useAsyncData (' files' , () => queryCollectionSearchSections (' content' , { ignoredTags: [' style' ] }))
15
+ const { data : files } = useLazyAsyncData (' search' , () => queryCollectionSearchSections (' content' ), {
16
+ server: false
17
+ })
18
+
19
+ const searchTerm = ref (' ' )
20
+
21
+ // watch(searchTerm, debounce((query: string) => {
22
+ // if (!query) {
23
+ // return
24
+ // }
25
+
26
+ // useTrackEvent('Search', { props: { query: `${query} - ${searchTerm.value?.commandPaletteRef.results.length} results` } })
27
+ // }, 500))
15
28
16
29
const links = computed (() => [{
17
30
label: ' Docs' ,
@@ -68,7 +81,33 @@ useServerSeoMeta({
68
81
twitterCard: ' summary_large_image'
69
82
})
70
83
71
- provide (' navigation' , navigation )
84
+ const { framework, frameworks } = useSharedData ()
85
+
86
+ function filterFrameworkItems(items : any []) {
87
+ return items ?.filter (item => ! item .framework || item .framework === framework .value )
88
+ }
89
+
90
+ function processNavigationItem(item : any ): any {
91
+ if (item .shadow ) {
92
+ const matchingChild = filterFrameworkItems (item .children )?.[0 ]
93
+ return matchingChild
94
+ ? {
95
+ ... matchingChild ,
96
+ title: item .title ,
97
+ children: matchingChild .children ? processNavigationItem (matchingChild ) : undefined
98
+ }
99
+ : item
100
+ }
101
+
102
+ return {
103
+ ... item ,
104
+ children: item .children ?.length ? filterFrameworkItems (item .children )?.map (processNavigationItem ) : undefined
105
+ }
106
+ }
107
+
108
+ const filteredNavigation = computed (() => navigation .value ?.map (processNavigationItem ))
109
+
110
+ provide (' navigation' , filteredNavigation )
72
111
</script >
73
112
74
113
<template >
@@ -84,7 +123,17 @@ provide('navigation', navigation)
84
123
<Footer />
85
124
86
125
<ClientOnly >
87
- <LazyUContentSearch :files =" files" :navigation =" navigation" :fuse =" { resultLimit: 42 }" />
126
+ <LazyUContentSearch
127
+ v-model:search-term =" searchTerm"
128
+ :files =" files"
129
+ :groups =" [{
130
+ id: 'framework',
131
+ label: 'Framework',
132
+ items: frameworks
133
+ }]"
134
+ :navigation =" filteredNavigation"
135
+ :fuse =" { resultLimit: 42 }"
136
+ />
88
137
</ClientOnly >
89
138
</UApp >
90
139
</template >
0 commit comments