Skip to content

Commit

Permalink
docs: track search
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Sep 14, 2023
1 parent 4127caa commit fbfa14a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions docs/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Footer />

<ClientOnly>
<LazyUDocsSearch :files="files" :navigation="navigation" />
<LazyUDocsSearch ref="searchRef" :files="files" :navigation="navigation" />
</ClientOnly>

<UNotifications>
Expand All @@ -27,18 +27,20 @@

<script setup lang="ts">
import { withoutTrailingSlash } from 'ufo'
import { debounce } from 'perfect-debounce'

const searchRef = ref()

const route = useRoute()
const colorMode = useColorMode()
const { prefix, removePrefixFromNavigation, removePrefixFromFiles } = useContentSource()

const { data: nav } = await useAsyncData('navigation', () => fetchContentNavigation())

const { data: search } = useLazyFetch('/api/search.json', {
default: () => [],
server: false
})
const { data: search } = useLazyFetch('/api/search.json', { default: () => [], server: false })

// Computed

const navigation = computed(() => {
const navigation = nav.value.find(link => link._path === prefix.value)?.children || []

Expand All @@ -53,7 +55,18 @@ const files = computed(() => {

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

useHead({
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
Expand All @@ -74,6 +87,7 @@ useServerSeoMeta({
})

// Provide

provide('navigation', navigation)
provide('files', files)
</script>

1 comment on commit fbfa14a

@vercel
Copy link

@vercel vercel bot commented on fbfa14a Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxt-js.vercel.app
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com

Please sign in to comment.