/
gatsby-node.js
37 lines (33 loc) · 867 Bytes
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const dotenv = require("dotenv").config();
const { Client } = require("@notionhq/client");
const notion = new Client({
auth: process.env.GATSBY_NOTION_TOKEN,
});
const database_id = process.env.GATSBY_NOTION_DATABASE_ID;
const getEvents = async () => {
const payload = {
path: `databases/${database_id}/query`,
method: "POST",
};
const { results } = await notion.request(payload);
console.log(results);
return results;
};
exports.sourceNodes = async ({
actions: { createNode },
createNodeId,
createContentDigest,
}) => {
const events = await getEvents();
events.forEach((event) => {
const newNode = {
content: { ...event },
id: createNodeId(`NotionEvent-${event.id}`),
internal: {
type: "NotionEvent",
contentDigest: createContentDigest(event),
},
};
createNode(newNode);
});
};