Skip to content

Commit 73be200

Browse files
committed
docs(app): hide empty categories using class
Fixes #4792
1 parent 2aca598 commit 73be200

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

docs/app/layouts/docs.vue

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { ContentNavigationItem } from '@nuxt/content'
33
import { findPageChildren } from '@nuxt/content/utils'
44
55
const route = useRoute()
6-
const { framework } = useSharedData()
76
87
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
98
@@ -35,7 +34,8 @@ const categories = {
3534
title: 'Page'
3635
}, {
3736
id: 'content',
38-
title: 'Content'
37+
title: 'Content',
38+
framework: 'nuxt'
3939
}, {
4040
id: 'dashboard',
4141
title: 'Dashboard'
@@ -51,20 +51,8 @@ const categories = {
5151
}]
5252
}
5353
54-
function filterChildrenByFramework(items: ContentNavigationItem[]): ContentNavigationItem[] {
55-
return items.filter((child) => {
56-
if (!child.framework) {
57-
return true
58-
}
59-
60-
return child.framework === framework.value
61-
})
62-
}
63-
6454
function groupChildrenByCategory(items: ContentNavigationItem[], slug: string): ContentNavigationItem[] {
65-
const filteredItems = filterChildrenByFramework(items)
66-
67-
const childrenGroupedByCategory = filteredItems.reduce((acc, child) => {
55+
const childrenGroupedByCategory = items.reduce((acc, child) => {
6856
if (child.category) {
6957
acc[child.category as string] = [...(acc[child.category as string] || []), child]
7058
} else {
@@ -73,22 +61,22 @@ function groupChildrenByCategory(items: ContentNavigationItem[], slug: string):
7361
return acc
7462
}, {} as Record<string, ContentNavigationItem[]>)
7563
76-
const grouped = categories[slug as keyof typeof categories]?.map(category => ({
77-
...category,
64+
const groups: ContentNavigationItem[] = categories[slug as keyof typeof categories]?.map(category => ({
65+
title: category.title,
7866
path: `/docs/${slug}`,
67+
class: 'framework' in category ? [`${category.framework}-only`] : undefined,
7968
children: childrenGroupedByCategory[category.id]
80-
}))?.filter(category => category.children?.length) || []
69+
}))?.filter(group => group.children?.length) || []
8170
8271
if (childrenGroupedByCategory.__overview && childrenGroupedByCategory.__overview.length > 0) {
83-
grouped.unshift({
84-
id: 'overview',
72+
groups.unshift({
8573
title: 'Overview',
8674
path: `/docs/${slug}`,
8775
children: childrenGroupedByCategory.__overview
8876
})
8977
}
9078
91-
return grouped
79+
return groups
9280
}
9381
9482
const children = computed(() => {

0 commit comments

Comments
 (0)