|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { ContentNavigationItem } from '@nuxt/content' |
| 3 | +import type { NavigationMenuItem } from '@nuxt/ui' |
| 4 | +
|
| 5 | +const { version } = useRuntimeConfig().public |
| 6 | +
|
| 7 | +const navigation = inject<Ref<ContentNavigationItem[]>>('navigation') |
| 8 | +const links = parseNavigation(navigation) |
| 9 | +
|
| 10 | +const { header } = useAppConfig() |
| 11 | +
|
| 12 | +function parseNavigation(contentNavigation?: Ref<ContentNavigationItem[]>): Ref<NavigationMenuItem[]> { |
| 13 | + return computed(() => { |
| 14 | + if (!contentNavigation?.value) return [] |
| 15 | +
|
| 16 | + const navigation = contentNavigation.value |
| 17 | + const items: NavigationMenuItem[] = [] |
| 18 | +
|
| 19 | + navigation.forEach((item) => { |
| 20 | + const children = item.children?.map(child => ({ |
| 21 | + label: child.title, |
| 22 | + to: child.page !== false |
| 23 | + ? child.path |
| 24 | + : undefined, |
| 25 | + icon: child.icon as string | undefined, |
| 26 | + children: child.children |
| 27 | + ? child.children.map(subChild => ({ |
| 28 | + label: subChild.title, |
| 29 | + to: subChild.page !== false |
| 30 | + ? subChild.path |
| 31 | + : undefined, |
| 32 | + })) |
| 33 | + : undefined, |
| 34 | + })) |
| 35 | +
|
| 36 | + items.push({ |
| 37 | + label: item.title, |
| 38 | + to: item.page !== false |
| 39 | + ? item.path |
| 40 | + : undefined, |
| 41 | + icon: item.icon as string | undefined, |
| 42 | + children, |
| 43 | + }) |
| 44 | + }) |
| 45 | +
|
| 46 | + return items |
| 47 | + }) |
| 48 | +} |
| 49 | +</script> |
| 50 | + |
| 51 | +<template> |
| 52 | + <UHeader |
| 53 | + :ui="{ center: 'flex-1' }" |
| 54 | + :to="header.to" |
| 55 | + :title="header.title" |
| 56 | + > |
| 57 | + <UNavigationMenu :items="links" variant="link" class="w-full justify-center" /> |
| 58 | + |
| 59 | + <template #left> |
| 60 | + <NuxtLink |
| 61 | + :to="header.to" |
| 62 | + class="flex items-end gap-2 font-bold text-xl text-[var(--ui-text-highlighted)] min-w-0 focus-visible:outline-[var(--ui-primary)]" |
| 63 | + > |
| 64 | + {{ header.title }} |
| 65 | + |
| 66 | + <UBadge |
| 67 | + :label="`v${version}`" |
| 68 | + variant="subtle" |
| 69 | + size="sm" |
| 70 | + class="font-semibold inline-block truncate place-self-center" |
| 71 | + /> |
| 72 | + </NuxtLink> |
| 73 | + </template> |
| 74 | + |
| 75 | + <template #body> |
| 76 | + <UContentNavigation |
| 77 | + highlight |
| 78 | + :navigation="navigation" |
| 79 | + /> |
| 80 | + </template> |
| 81 | + |
| 82 | + <template #right> |
| 83 | + <UContentSearchButton v-if="header.search" /> |
| 84 | + |
| 85 | + <UColorModeButton v-if="header.colorMode" /> |
| 86 | + |
| 87 | + <template v-if="header.links"> |
| 88 | + <UButton |
| 89 | + v-for="(link, index) of header.links" |
| 90 | + :key="index" |
| 91 | + v-bind="{ color: 'neutral', variant: 'ghost', ...link }" |
| 92 | + /> |
| 93 | + </template> |
| 94 | + </template> |
| 95 | + </UHeader> |
| 96 | +</template> |
0 commit comments