Skip to content

Commit b027c31

Browse files
committed
Adding separate return value for parent and children
1 parent 6018e13 commit b027c31

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

components/notion/actions/retrieve-block/retrieve-block.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,20 @@ export default {
3333
},
3434
},
3535
async run({ $ }) {
36-
let markdownContent;
37-
if (this.retrieveMarkdown) {
38-
markdownContent = await this.notion.getPageAsMarkdown(this.blockId);
39-
}
40-
4136
const { retrieveChildren } = this;
4237
const subpagesOnly = retrieveChildren === "Sub-Pages Only";
43-
44-
const block = await this.notion.retrieveBlock(this.blockId);
4538
const shouldRetrieveChildren = [
4639
true,
4740
"All Children",
4841
"Sub-Pages Only",
4942
].includes(retrieveChildren);
43+
44+
let markdownContent;
45+
if (this.retrieveMarkdown) {
46+
markdownContent = await this.notion.getPageAsMarkdown(this.blockId, shouldRetrieveChildren);
47+
}
48+
49+
const block = await this.notion.retrieveBlock(this.blockId);
5050
if (shouldRetrieveChildren) {
5151
block.children = await this.notion.retrieveBlockChildren(block, subpagesOnly);
5252
}

components/notion/notion.app.mjs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,20 @@ export default {
357357

358358
return response.results;
359359
},
360-
async getPageAsMarkdown(pageId) {
361-
const notionClient = this._getNotionClient();
360+
async getPageAsMarkdown(pageId, shouldRetrieveChildren) {
361+
const notion = this._getNotionClient();
362362

363363
const n2m = new NotionToMarkdown({
364-
notionClient,
364+
notionClient: notion,
365+
config: {
366+
separateChildPage: true,
367+
},
365368
});
366369
const blocks = await n2m.pageToMarkdown(pageId);
367-
return n2m.toMarkdownString(blocks).parent;
370+
const output = n2m.toMarkdownString(blocks);
371+
return shouldRetrieveChildren
372+
? output
373+
: output.parent;
368374
},
369375
},
370376
};

0 commit comments

Comments
 (0)