Skip to content

Commit

Permalink
Fix: notion document block ordering (#3132)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperolet authored Jan 10, 2024
1 parent 7c277c1 commit d57778f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions connectors/src/connectors/notion/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,8 @@ export async function renderAndUpsertPageFromCache({
const topLevelBlocks = blockCacheEntries.filter(
(b) => b.parentBlockId === null
);
topLevelBlocks.sort((a, b) => a.indexInParent - b.indexInParent);

const blocksByParentId: Record<string, NotionConnectorBlockCacheEntry[]> = {};
for (const blockCacheEntry of blockCacheEntries) {
if (!blockCacheEntry.parentBlockId) continue;
Expand Down Expand Up @@ -1572,6 +1574,7 @@ export async function renderAndUpsertPageFromCache({
}
let renderedBlock = b.blockText ? `${indent}${b.blockText}\n` : "";
const children = blocksByParentId[b.notionBlockId] ?? [];
children.sort((a, b) => a.indexInParent - b.indexInParent);
for (const child of children) {
renderedBlock += renderBlock(child, `- ${indent}`);
}
Expand Down

0 comments on commit d57778f

Please sign in to comment.