From 27cc0088138b09d04f2947d2c4b00caf4eb0f1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Arod?= Date: Wed, 18 Dec 2024 10:26:16 +0100 Subject: [PATCH] fix: workaround Notion API limit on richtext length --- .../v2/createSingleValueStatListItemBlock.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/notion/publish/v2/createSingleValueStatListItemBlock.ts b/src/notion/publish/v2/createSingleValueStatListItemBlock.ts index f5e0340..ce753a4 100644 --- a/src/notion/publish/v2/createSingleValueStatListItemBlock.ts +++ b/src/notion/publish/v2/createSingleValueStatListItemBlock.ts @@ -1,7 +1,7 @@ import { formatValue } from "../../../format/formatValue"; import { ValueFormatOptions } from "../../../format/ValueFormatOptions"; import { StatsData } from "../../../statistiques/v2/desc/StatsDesc"; -import { isNumber } from "lodash"; +import { chunk, isNumber } from "lodash"; import { BlockObjectRequest } from "@notionhq/client/build/src/api-endpoints"; export function createSingleValueStatListItemBlock( @@ -9,9 +9,9 @@ export function createSingleValueStatListItemBlock( formatOptions: ValueFormatOptions, data: StatsData ): BlockObjectRequest { - if (isNumber(data) ) { + if (isNumber(data)) { return bulletedListNumberData(label, data, formatOptions); - } else if (data.relatedPageIds.length === 0 ) { + } else if (data.relatedPageIds.length === 0) { return bulletedListNumberData(label, data.value, formatOptions); } else { return { @@ -32,19 +32,27 @@ export function createSingleValueStatListItemBlock( content: "Liens: ", }, }, - ...data.relatedPageIds.map((pageId) => - createPageMentionRichTextElement(pageId) - ), ], }, }, + ...chunk(data.relatedPageIds, 100).map((pageIdsChunk) => ({ + paragraph: { + rich_text: pageIdsChunk.map((pageId) => + createPageMentionRichTextElement(pageId) + ), + }, + })), ], }, }; } } -function bulletedListNumberData(label: string, data: number, formatOptions: ValueFormatOptions): BlockObjectRequest { +function bulletedListNumberData( + label: string, + data: number, + formatOptions: ValueFormatOptions +): BlockObjectRequest { return { bulleted_list_item: { rich_text: [