Skip to content

Commit fc707af

Browse files
committed
Fix Notion record map nested value.value structure for react-notion-x
1 parent 3e82228 commit fc707af

File tree

1 file changed

+17
-1
lines changed
  • apps/web/app/tracks/[...trackIds]

1 file changed

+17
-1
lines changed

apps/web/app/tracks/[...trackIds]/page.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import { LessonView } from "../../../components/LessonView";
66

77
const notion = new NotionAPI();
88
export const dynamic = "force-dynamic";
9+
10+
// Normalize Notion record map to handle nested value.value structure
11+
function normalizeRecordMap(recordMap: any) {
12+
if (!recordMap?.block) return recordMap;
13+
const normalizedBlock: any = {};
14+
for (const [key, block] of Object.entries(recordMap.block) as any) {
15+
if (block?.value?.value) {
16+
normalizedBlock[key] = { ...block, value: block.value.value };
17+
} else {
18+
normalizedBlock[key] = block;
19+
}
20+
}
21+
return { ...recordMap, block: normalizedBlock };
22+
}
23+
924
// Dynamic Metadata
1025
export async function generateMetadata({ params }: { params: { trackIds: string[] } }) {
1126
const trackId = params.trackIds[0] || "";
@@ -59,7 +74,8 @@ export default async function TrackComponent({ params }: { params: { trackIds: s
5974
}
6075

6176
if (problemDetails?.notionDocId) {
62-
notionRecordMap = await notion.getPage(problemDetails.notionDocId);
77+
const rawRecordMap = await notion.getPage(problemDetails.notionDocId);
78+
notionRecordMap = normalizeRecordMap(rawRecordMap);
6379
}
6480

6581
if (trackDetails && problemDetails) {

0 commit comments

Comments
 (0)