mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-28 19:00:35 +01:00
docs: improve multi-source handling (#682)
This commit is contained in:
21
docs/app.vue
21
docs/app.vue
@@ -10,7 +10,7 @@
|
||||
<Footer />
|
||||
|
||||
<ClientOnly>
|
||||
<LazyUDocsSearch ref="searchRef" :files="files" :navigation="navigation" />
|
||||
<LazyUDocsSearch ref="searchRef" :files="files" :navigation="navigation" :groups="groups" />
|
||||
</ClientOnly>
|
||||
|
||||
<UNotifications>
|
||||
@@ -28,29 +28,32 @@
|
||||
<script setup lang="ts">
|
||||
import { withoutTrailingSlash } from 'ufo'
|
||||
import { debounce } from 'perfect-debounce'
|
||||
import type { ParsedContent } from '@nuxt/content/dist/runtime/types'
|
||||
|
||||
const searchRef = ref()
|
||||
|
||||
const route = useRoute()
|
||||
const colorMode = useColorMode()
|
||||
const { prefix, removePrefixFromNavigation, removePrefixFromFiles } = useContentSource()
|
||||
const { branch, branches } = useContentSource()
|
||||
|
||||
const { data: nav } = await useAsyncData('navigation', () => fetchContentNavigation())
|
||||
|
||||
const { data: search } = useLazyFetch('/api/search.json', { default: () => [], server: false })
|
||||
const { data: files } = useLazyFetch<ParsedContent[]>('/api/search.json', { default: () => [], server: false })
|
||||
|
||||
// Computed
|
||||
|
||||
const navigation = computed(() => {
|
||||
const navigation = nav.value.find(link => link._path === prefix.value)?.children || []
|
||||
const main = nav.value.filter(item => item._path !== '/dev')
|
||||
const dev = nav.value.find(item => item._path === '/dev')?.children
|
||||
|
||||
return prefix.value === '/main' ? removePrefixFromNavigation(navigation) : navigation
|
||||
return branch.value?.name === 'dev' ? dev : main
|
||||
})
|
||||
|
||||
const files = computed(() => {
|
||||
const files = search.value.filter(file => file._path.startsWith(prefix.value))
|
||||
const groups = computed(() => {
|
||||
if (route.path === '/') {
|
||||
return []
|
||||
}
|
||||
|
||||
return prefix.value === '/main' ? removePrefixFromFiles(files) : files
|
||||
return [{ key: 'branch', label: 'Branch', commands: branches.value }]
|
||||
})
|
||||
|
||||
const color = computed(() => colorMode.value === 'dark' ? '#18181b' : 'white')
|
||||
|
||||
Reference in New Issue
Block a user