Skip to content

Commit 4d7fe16

Browse files
authored
feat(layout): handle deeply nested content (#1190)
1 parent 9f797a6 commit 4d7fe16

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

layer/app/layouts/default.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
22
import type { ContentNavigationItem } from '@nuxt/content'
3+
import { flattenNavigation } from '../utils/navigation'
34
45
const route = useRoute()
56
const docsNavigation = inject<Ref<ContentNavigationItem[]>>('navigation')
6-
const docsLink = computed(() => docsNavigation?.value.flatMap(item => item.children || [item]) || [])
7+
const docsLink = computed(() => flattenNavigation(docsNavigation?.value))
78
const isDocs = computed(() => docsLink.value.findIndex(item => item.path === route.path) !== -1)
89
</script>
910

layer/app/utils/navigation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ContentNavigationItem } from '@nuxt/content'
2+
3+
export const flattenNavigation = (items?: ContentNavigationItem[]): ContentNavigationItem[] => items?.flatMap(
4+
item => item.children
5+
? flattenNavigation(item.children)
6+
: [item],
7+
) || []

0 commit comments

Comments
 (0)