@@ -11,12 +11,12 @@ export class RecursiveBodyRenderer {
11
11
constructor (
12
12
readonly publicApi : Client ,
13
13
readonly blockRenderer : BlockRenderer
14
- ) { }
14
+ ) { }
15
15
16
16
async renderBody (
17
17
page : Page ,
18
18
assets : AssetWriter ,
19
- context : RenderingLoggingContext ,
19
+ context : RenderingLoggingContext
20
20
) : Promise < string > {
21
21
debug ( "begin rendering body of page " + page . id , page . properties ) ;
22
22
@@ -42,24 +42,28 @@ export class RecursiveBodyRenderer {
42
42
assets : AssetWriter ,
43
43
context : RenderingLoggingContext
44
44
) : Promise < string > {
45
- const parentBlock = await this . blockRenderer . renderBlock ( block , assets , context ) ;
46
- const parentLines = this . indent ( parentBlock . lines , indent ) ;
45
+ const parentBlock = await this . blockRenderer . renderBlock (
46
+ block ,
47
+ assets ,
48
+ context
49
+ ) ;
50
+ const parentLines = parentBlock && this . indent ( parentBlock . lines , indent ) ;
47
51
48
52
// due to the way the Notion API is built, we need to recurisvely retrieve child
49
53
// blocks, see https://developers.notion.com/reference/retrieve-a-block
50
54
// "If a block contains the key has_children: true, use the Retrieve block children endpoint to get the list of children"
51
55
const children = block . has_children
52
56
? ( await this . publicApi . blocks . children . list ( { block_id : block . id } ) )
53
- . results
57
+ . results
54
58
: [ ] ;
55
59
56
- const childIndent = indent + " " . repeat ( parentBlock . childIndent || 0 ) ;
60
+ const childIndent = indent + " " . repeat ( parentBlock ? .childIndent || 0 ) ;
57
61
const renderChilds = children . map (
58
62
async ( x ) => await this . renderBlock ( x , childIndent , assets , context )
59
63
) ;
60
64
const childLines = await Promise . all ( renderChilds ) ;
61
65
62
- return [ parentLines , ...childLines ] . join ( "\n\n" ) ;
66
+ return [ parentLines , ...childLines ] . filter ( ( x ) => ! ! x ) . join ( "\n\n" ) ;
63
67
}
64
68
65
69
private indent ( content : string , indent : string ) {
0 commit comments