mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-25 09:20:36 +01:00
docs: track search
This commit is contained in:
24
docs/app.vue
24
docs/app.vue
@@ -10,7 +10,7 @@
|
|||||||
<Footer />
|
<Footer />
|
||||||
|
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<LazyUDocsSearch :files="files" :navigation="navigation" />
|
<LazyUDocsSearch ref="searchRef" :files="files" :navigation="navigation" />
|
||||||
</ClientOnly>
|
</ClientOnly>
|
||||||
|
|
||||||
<UNotifications>
|
<UNotifications>
|
||||||
@@ -27,18 +27,20 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
|
import { debounce } from 'perfect-debounce'
|
||||||
|
|
||||||
|
const searchRef = ref()
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const colorMode = useColorMode()
|
const colorMode = useColorMode()
|
||||||
const { prefix, removePrefixFromNavigation, removePrefixFromFiles } = useContentSource()
|
const { prefix, removePrefixFromNavigation, removePrefixFromFiles } = useContentSource()
|
||||||
|
|
||||||
const { data: nav } = await useAsyncData('navigation', () => fetchContentNavigation())
|
const { data: nav } = await useAsyncData('navigation', () => fetchContentNavigation())
|
||||||
|
|
||||||
const { data: search } = useLazyFetch('/api/search.json', {
|
const { data: search } = useLazyFetch('/api/search.json', { default: () => [], server: false })
|
||||||
default: () => [],
|
|
||||||
server: false
|
|
||||||
})
|
|
||||||
|
|
||||||
// Computed
|
// Computed
|
||||||
|
|
||||||
const navigation = computed(() => {
|
const navigation = computed(() => {
|
||||||
const navigation = nav.value.find(link => link._path === prefix.value)?.children || []
|
const navigation = nav.value.find(link => link._path === prefix.value)?.children || []
|
||||||
|
|
||||||
@@ -53,7 +55,18 @@ const files = computed(() => {
|
|||||||
|
|
||||||
const color = computed(() => colorMode.value === 'dark' ? '#18181b' : 'white')
|
const color = computed(() => colorMode.value === 'dark' ? '#18181b' : 'white')
|
||||||
|
|
||||||
|
// Watch
|
||||||
|
|
||||||
|
watch(() => searchRef.value?.commandPaletteRef?.query, debounce((query: string) => {
|
||||||
|
if (!query) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
useTrackEvent('Search', { props: { query, results: `${searchRef.value?.commandPaletteRef.results.length}` } })
|
||||||
|
}, 500))
|
||||||
|
|
||||||
// Head
|
// Head
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
meta: [
|
meta: [
|
||||||
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
||||||
@@ -74,6 +87,7 @@ useServerSeoMeta({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Provide
|
// Provide
|
||||||
|
|
||||||
provide('navigation', navigation)
|
provide('navigation', navigation)
|
||||||
provide('files', files)
|
provide('files', files)
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user