Skip to content

Commit b139cb6

Browse files
committed
Adding markdown page retrieval
1 parent f415ffd commit b139cb6

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "notion-retrieve-block",
55
name: "Retrieve Block",
66
description: "Get details of a block, which can be text, lists, media, a page, among others. [See the documentation](https://developers.notion.com/reference/retrieve-a-block)",
7-
version: "0.0.6",
7+
version: "0.1.0",
88
type: "action",
99
props: {
1010
notion,
@@ -23,8 +23,20 @@ export default {
2323
optional: true,
2424
default: false,
2525
},
26+
retrieveMarkdown: {
27+
type: "boolean",
28+
label: "Retrieve as Markdown",
29+
description: "Return the page content as markdown instead of block objects.",
30+
optional: true,
31+
},
2632
},
2733
async run({ $ }) {
34+
if (this.retrieveMarkdown) {
35+
const response = await this.notion.getPageAsMarkdown(this.blockId);
36+
$.export("$summary", "Successfully retrieved page as markdown");
37+
return response;
38+
}
39+
2840
const block = await this.notion.retrieveBlock(this.blockId);
2941
if (this.retrieveChildren) {
3042
block.children = await this.notion.retrieveBlockChildren(block);

components/notion/notion.app.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import notion from "@notionhq/client";
22
import NOTION_META from "./common/notion-meta-selection.mjs";
33
import { ConfigurationError } from "@pipedream/platform";
4+
import { NotionConverter } from "notion-to-md";
5+
import { DefaultExporter } from "notion-to-md/plugins/exporter";
46

57
export default {
68
type: "app",
@@ -355,5 +357,19 @@ export default {
355357

356358
return response.results;
357359
},
360+
async getPageAsMarkdown(pageId) {
361+
const client = this._getNotionClient();
362+
363+
const buffer = {};
364+
const exporter = new DefaultExporter({
365+
outputType: "buffer",
366+
buffer,
367+
});
368+
369+
const n2m = new NotionConverter(client).withExporter(exporter);
370+
await n2m.convert(pageId);
371+
372+
return Object.values(buffer)[0];
373+
},
358374
},
359375
};

0 commit comments

Comments
 (0)