Skip to content

Commit

Permalink
docs: improve performances (#570)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
Atinux and benjamincanac committed Aug 30, 2023
1 parent ffd6d68 commit 8ce75a9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
34 changes: 16 additions & 18 deletions docs/app.vue
Expand Up @@ -9,7 +9,6 @@
<template #left>
<UAside :links="anchors">
<BranchSelect />

<UNavigationTree :links="mapContentNavigation(navigation)" />
</UAside>
</template>
Expand All @@ -20,7 +19,7 @@
</UMain>

<ClientOnly>
<UDocsSearch :files="files" :navigation="navigation" />
<LazyUDocsSearch :files="files" :navigation="navigation" />
</ClientOnly>

<UNotifications>
Expand All @@ -40,24 +39,11 @@ const colorMode = useColorMode()
const { prefix, removePrefixFromNavigation, removePrefixFromFiles } = useContentSource()
const { mapContentNavigation } = useElementsHelpers()
const { data: navigation } = await useLazyAsyncData('navigation', () => fetchContentNavigation(), {
default: () => [],
transform: (navigation) => {
navigation = navigation.find(link => link._path === prefix.value)?.children || []
return prefix.value === '/main' ? removePrefixFromNavigation(navigation) : navigation
},
watch: [prefix]
})
const { data: nav } = await useAsyncData('navigation', () => fetchContentNavigation())
const { data: files } = await useLazyAsyncData('files', () => queryContent().where({ _type: 'markdown', navigation: { $ne: false } }).find(), {
const { data: search } = useLazyFetch('/api/search.json', {
default: () => [],
transform: (files) => {
files = files.filter(file => file._path.startsWith(prefix.value))
return prefix.value === '/main' ? removePrefixFromFiles(files) : files
},
watch: [prefix]
server: false
})
const anchors = [{
Expand All @@ -78,6 +64,18 @@ const anchors = [{
// Computed
const navigation = computed(() => {
const navigation = nav.value.find(link => link._path === prefix.value)?.children || []
return prefix.value === '/main' ? removePrefixFromNavigation(navigation) : navigation
})
const files = computed(() => {
const files = search.value.filter(file => file._path.startsWith(prefix.value))
return prefix.value === '/main' ? removePrefixFromFiles(files) : files
})
const color = computed(() => colorMode.value === 'dark' ? '#18181b' : 'white')
// Head
Expand Down
1 change: 0 additions & 1 deletion docs/components/Header.vue
Expand Up @@ -21,7 +21,6 @@

<template #panel>
<BranchSelect />

<UNavigationTree :links="mapContentNavigation(navigation)" />
</template>
</UHeader>
Expand Down
22 changes: 18 additions & 4 deletions docs/nuxt.config.ts
Expand Up @@ -57,12 +57,15 @@ export default defineNuxtConfig({
},
nitro: {
prerender: {
routes: ['/getting-started', '/dev/getting-started']
// Waiting for https://github.com/nuxt/nuxt/issues/22763
concurrency: 1,
routes: [
'/getting-started',
'/dev/getting-started',
'/api/search.json'
]
}
},
experimental: {
payloadExtraction: false
},
componentMeta: {
globalsOnly: true,
exclude: [resolve('./components'), resolve('@nuxthq/elements/components')],
Expand All @@ -76,5 +79,16 @@ export default defineNuxtConfig({
typescript: {
strict: false,
includeWorkspace: true
},
hooks: {
// TODO: Uncomment after Nuxt v3.7 upgrade
// Related to https://github.com/nuxt/nuxt/pull/22558
// 'components:extend': (components) => {
// components.forEach((component) => {
// if (component.global) {
// component.global = 'sync'
// }
// })
// }
}
})
5 changes: 5 additions & 0 deletions docs/server/api/search.json.get.ts
@@ -0,0 +1,5 @@
import { serverQueryContent } from '#content/server'

export default eventHandler(async (event) => {
return serverQueryContent(event).where({ _type: 'markdown', navigation: { $ne: false } }).find()
})
2 changes: 1 addition & 1 deletion src/runtime/plugins/colors.ts
@@ -1,6 +1,6 @@
import { computed } from 'vue'
import { hexToRgb } from '../utils'
import { defineNuxtPlugin, useHead, useAppConfig, useNuxtApp } from '#imports'
import { defineNuxtPlugin, useAppConfig } from '#imports'
import colors from '#tailwind-config/theme/colors'

export default defineNuxtPlugin((nuxtApp) => {
Expand Down

1 comment on commit 8ce75a9

@vercel
Copy link

@vercel vercel bot commented on 8ce75a9 Aug 30, 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.nuxtlabs.com
ui-git-dev-nuxtlabs.vercel.app
ui-nuxtlabs.vercel.app

Please sign in to comment.