Skip to content

Commit 572d7c5

Browse files
authored
omit topics with no docs (#481)
1 parent c8b2ace commit 572d7c5

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/app/(frontend)/(pages)/docs/fetchTopicsForSidebar.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,37 @@ export const fetchTopicsForSidebar = async ({
3333
const docs = result.docs
3434

3535
const topicGroups: TopicGroupForNav[] = topicOrder[version]
36-
.map(
37-
({ groupLabel, topics: topicsGroup }) => ({
38-
groupLabel,
39-
topics: topicsGroup.map((key) => {
36+
.map(({ groupLabel, topics: topicsGroup }) => ({
37+
groupLabel,
38+
topics: topicsGroup
39+
.map((key) => {
4040
const topicSlug = key.toLowerCase()
4141

4242
const docsForTopic = docs.filter(
4343
(doc) => doc.topic === topicSlug && doc.topicGroup === groupLabel,
4444
)
4545

4646
const parsedDocs: ParsedDocForNav[] = docsForTopic
47-
.map((doc) => {
48-
return {
49-
slug: doc.slug,
50-
label: doc.label ?? '',
51-
order: doc.order ?? 0,
52-
title: doc.title ?? '',
53-
}
54-
})
47+
.map((doc) => ({
48+
slug: doc.slug,
49+
label: doc.label ?? '',
50+
order: doc.order ?? 0,
51+
title: doc.title ?? '',
52+
}))
5553
.filter(Boolean) as ParsedDocForNav[]
5654

55+
if (parsedDocs.length === 0) {
56+
return null // Omit topics with no docs
57+
}
58+
5759
return {
5860
slug: topicSlug,
5961
docs: parsedDocs.sort((a, b) => a.order - b.order),
6062
label: key,
6163
} as TopicForNav
62-
}),
63-
}),
64-
[],
65-
)
64+
})
65+
.filter(Boolean), // Remove nulls (topics with no docs)
66+
}))
6667
.filter(Boolean) as TopicGroupForNav[]
6768

6869
return topicGroups

0 commit comments

Comments
 (0)