Skip to content

Commit 2cc39d6

Browse files
authored
fix tocitem serialization error (#56348)
1 parent eecae95 commit 2cc39d6

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/frame/middleware/context/generic-toc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async function getTocItems(node: Tree, context: Context, opts: Options): Promise
122122
node.childPages.filter(filterHidden).map(async (child) => {
123123
const { page } = child
124124
const title = await page.renderProp('rawTitle', context, { textOnly: true })
125-
const octicon = page.octicon ? page.octicon : null
125+
const octicon = page.octicon ?? null
126126
const category = page.category ? page.category : null
127127
const complexity = page.complexity ? page.complexity : null
128128
const industry = page.industry ? page.industry : null

src/landings/components/CategoryLanding.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const CategoryLanding = () => {
141141
<CookBookArticleCard
142142
title={item.title}
143143
description={item.intro!}
144-
icon={item.octicon}
144+
icon={item.octicon ?? undefined}
145145
tags={[
146146
...(item.industry || []),
147147
...(item.category || []),

src/landings/types.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export type BaseTocItem = {
33
fullPath: string
44
title: string
5-
intro?: string
5+
intro?: string | null
66
}
77

88
// Valid octicon types that match the CookBookArticleCard component
@@ -23,19 +23,19 @@ export type ValidOcticon =
2323

2424
// Extended type for child TOC items with additional metadata
2525
export type ChildTocItem = BaseTocItem & {
26-
octicon?: ValidOcticon
27-
category?: string[]
28-
complexity?: string[]
29-
industry?: string[]
26+
octicon?: ValidOcticon | null
27+
category?: string[] | null
28+
complexity?: string[] | null
29+
industry?: string[] | null
3030
}
3131

3232
// Main TOC item type that can contain children
3333
export type TocItem = BaseTocItem & {
3434
childTocItems?: ChildTocItem[]
35-
octicon?: ValidOcticon
36-
category?: string[]
37-
complexity?: string[]
38-
industry?: string[]
35+
octicon?: ValidOcticon | null
36+
category?: string[] | null
37+
complexity?: string[] | null
38+
industry?: string[] | null
3939
}
4040

4141
// Type alias for article card components
@@ -90,11 +90,11 @@ export function mapRawTocItemToTocItem(raw: RawTocItem): TocItem {
9090
return {
9191
fullPath: raw.fullPath,
9292
title: raw.title,
93-
intro: raw.intro || undefined,
94-
octicon: isValidOcticon(raw.octicon) ? raw.octicon : undefined,
95-
category: raw.category || undefined,
96-
complexity: raw.complexity || undefined,
97-
industry: raw.industry || undefined,
93+
intro: raw.intro || null,
94+
octicon: isValidOcticon(raw.octicon) ? raw.octicon : null,
95+
category: raw.category || null,
96+
complexity: raw.complexity || null,
97+
industry: raw.industry || null,
9898
childTocItems: raw.childTocItems?.map(mapRawTocItemToTocItem),
9999
}
100100
}
@@ -104,7 +104,7 @@ export function mapRawTocItemToSimpleTocItem(raw: RawTocItem): SimpleTocItem {
104104
return {
105105
fullPath: raw.fullPath,
106106
title: raw.title,
107-
intro: raw.intro || undefined,
107+
...(raw.intro && { intro: raw.intro }),
108108
childTocItems: raw.childTocItems?.map((child) => ({
109109
fullPath: child.fullPath,
110110
title: child.title,

0 commit comments

Comments
 (0)