Skip to content

Commit 3080d9e

Browse files
committed
Add recursive mapping of entries for TOC in Column layout
1 parent af400d1 commit 3080d9e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/notion-utils/src/get-page-table-of-contents.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export const getPageTableOfContents = (
4747
}
4848
}
4949

50-
if (type === 'transclusion_container') {
50+
if (
51+
type === 'transclusion_container' ||
52+
type === 'column_list' ||
53+
type === 'column'
54+
) {
5155
return mapContentToEntries(block.content)
5256
}
5357
}
@@ -56,10 +60,15 @@ export const getPageTableOfContents = (
5660
})
5761
}
5862

59-
const toc = mapContentToEntries(page.content)
60-
// Synced blocks cannot be nested. So theoretically a 1-level flattening is enough.
61-
.flat()
62-
.filter(Boolean) as Array<TableOfContentsEntry>
63+
// Helper function to flatten nested results recursively
64+
function flattenResults(results: MapResult[]): TableOfContentsEntry[] {
65+
return results.flatMap((r) => {
66+
if (r == null) return []
67+
return Array.isArray(r) ? flattenResults(r) : [r]
68+
})
69+
}
70+
71+
const toc = flattenResults(mapContentToEntries(page.content))
6372

6473
const indentLevelStack = [
6574
{

0 commit comments

Comments
 (0)