File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
packages/notion-utils/src Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,12 @@ export const getPageTableOfContents = (
23
23
page : types . PageBlock ,
24
24
recordMap : types . ExtendedRecordMap
25
25
) : Array < TableOfContentsEntry > => {
26
- const toc = ( page . content ?? [ ] )
27
- . map ( ( blockId : string ) => {
26
+ type MapResult = TableOfContentsEntry | null | MapResult [ ]
27
+
28
+ // Maps `content` property to TOC entries.
29
+ // Pages and transclusion containers (synced blocks) both have the property.
30
+ function mapContentToEntries ( content ?: string [ ] ) : MapResult [ ] {
31
+ return ( content ?? [ ] ) . map ( ( blockId : string ) => {
28
32
const block = recordMap . block [ blockId ] ?. value
29
33
30
34
if ( block ) {
@@ -42,10 +46,19 @@ export const getPageTableOfContents = (
42
46
indentLevel : indentLevels [ type ]
43
47
}
44
48
}
49
+
50
+ if ( type === 'transclusion_container' ) {
51
+ return mapContentToEntries ( block . content )
52
+ }
45
53
}
46
54
47
55
return null
48
56
} )
57
+ }
58
+
59
+ const toc = mapContentToEntries ( page . content )
60
+ // Synced blocks cannot be nested. So theoretically a 1-level flattening is enough.
61
+ . flat ( )
49
62
. filter ( Boolean ) as Array < TableOfContentsEntry >
50
63
51
64
const indentLevelStack = [
You can’t perform that action at this time.
0 commit comments