Skip to content

Commit 2b18728

Browse files
authored
Notion markdown followup (#16214)
* pnpm * Adding more options to 'retrieve block' and adjusting response format * Version bumps
1 parent 87726b1 commit 2b18728

File tree

6 files changed

+39
-22
lines changed

6 files changed

+39
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
name: "Append Block to Parent",
88
description:
99
"Append new and/or existing blocks to the specified parent. [See the documentation](https://developers.notion.com/reference/patch-block-children)",
10-
version: "0.3.1",
10+
version: "0.3.2",
1111
type: "action",
1212
props: {
1313
notion,

components/notion/actions/duplicate-page/duplicate-page.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "notion-duplicate-page",
88
name: "Duplicate Page",
99
description: "Create a new page copied from an existing page block. [See the documentation](https://developers.notion.com/reference/post-page)",
10-
version: "0.0.11",
10+
version: "0.0.12",
1111
type: "action",
1212
props: {
1313
notion,

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "notion-retrieve-block",
55
name: "Retrieve Page Content",
66
description: "Get page content as block objects or markdown. Blocks can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)",
7-
version: "0.1.0",
7+
version: "0.2.0",
88
type: "action",
99
props: {
1010
notion,
@@ -15,33 +15,50 @@ export default {
1515
],
1616
},
1717
retrieveChildren: {
18-
type: "boolean",
19-
label: "Retrieve Content (Child Blocks)",
20-
description: "Retrieve all the children (recursively) for the specified page. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information",
18+
type: "string",
19+
label: "Retrieve Children",
20+
description: "Retrieve all the children (recursively) for the specified page, or optionally filter to include only sub-pages in the result. [See the documentation](https://developers.notion.com/reference/get-block-children) for more information",
2121
optional: true,
22-
default: false,
22+
options: [
23+
"All Children",
24+
"Sub-Pages Only",
25+
"None",
26+
],
2327
},
2428
retrieveMarkdown: {
2529
type: "boolean",
2630
label: "Retrieve as Markdown",
27-
description: "Return the page content as markdown instead of block objects.",
31+
description: "Additionally return the page content as markdown",
2832
optional: true,
2933
},
3034
},
3135
async run({ $ }) {
36+
let markdownContent;
3237
if (this.retrieveMarkdown) {
33-
const response = await this.notion.getPageAsMarkdown(this.blockId);
34-
$.export("$summary", "Successfully retrieved page as markdown");
35-
return response;
38+
markdownContent = await this.notion.getPageAsMarkdown(this.blockId);
3639
}
3740

41+
const { retrieveChildren } = this;
42+
const subpagesOnly = retrieveChildren === "Sub-Pages Only";
43+
3844
const block = await this.notion.retrieveBlock(this.blockId);
39-
if (this.retrieveChildren) {
40-
block.children = await this.notion.retrieveBlockChildren(block);
45+
if ([
46+
true,
47+
"All Children",
48+
"Sub-Pages Only",
49+
].includes(retrieveChildren)) {
50+
block.children = await this.notion.retrieveBlockChildren(block, subpagesOnly);
4151
}
42-
$.export("$summary", `Successfully retrieved block${this.retrieveChildren
43-
? ` with ${block.children.length ?? 0} children`
52+
$.export("$summary", `Successfully retrieved block${retrieveChildren
53+
? ` with ${block.children.length ?? 0} ${subpagesOnly
54+
? "sub-pages"
55+
: "children"}`
4456
: ""}`);
45-
return block;
57+
return markdownContent
58+
? {
59+
markdownContent,
60+
block,
61+
}
62+
: block;
4663
},
4764
};

components/notion/notion.app.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ export default {
325325
block_id: blockId,
326326
});
327327
},
328-
async retrieveBlockChildren(block, params = {}) {
328+
async retrieveBlockChildren(block, subpagesOnly = false) {
329+
const params = {};
329330
const children = [];
330331
if (!block.has_children) return children;
331332

@@ -335,11 +336,11 @@ export default {
335336
next_cursor: nextCursor,
336337
} = await this.listBlockChildren(block.id, params);
337338

338-
children.push(...results);
339+
children.push(...(results.filter((child) => !subpagesOnly || child.type === "child_page")));
339340
params.next_cursor = nextCursor;
340341
} while (params.next_cursor);
341342

342-
(await Promise.all(children.map((child) => this.retrieveBlockChildren(child))))
343+
(await Promise.all(children.map((child) => this.retrieveBlockChildren(child, subpagesOnly))))
343344
.forEach((c, i) => {
344345
children[i].children = c;
345346
});

components/notion/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notion",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Pipedream Notion Components",
55
"main": "notion.app.mjs",
66
"keywords": [

pnpm-lock.yaml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)