-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
33 lines (32 loc) · 964 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
import { getPages } from "./src/notion-api/get-pages";
import { getTitleByNotionPage } from "./src/util/parse";
import { NOTION_NODE_TYPE } from "./src/constants";
export async function sourceNodes(
{ actions, createContentDigest, createNodeId, reporter, cache },
{ token, databases = [] },
) {
for (const database of databases) {
const pages = await getPages(
{ token, databaseId: database.id, pageFilter: database.pageFilter, option: database.option },
reporter,
cache,
);
pages.forEach((page) => {
actions.createNode({
id: createNodeId(`${NOTION_NODE_TYPE}-${page.id}`),
parent: null,
children: [],
internal: {
type: NOTION_NODE_TYPE,
mediaType: "text/javascript",
contentDigest: createContentDigest(page),
},
databaseName: database.name,
title: getTitleByNotionPage(page),
json: JSON.stringify(page),
createdAt: page.created_time,
updatedAt: page.last_edited_time,
});
});
}
}