gatsby-source-notion-churnotion 1.0.36 → 1.0.38

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,8 +18,8 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, ge
18
18
  reporter.info(`[CHECK] BOOK page: ${page.id}`);
19
19
  const nodeId = createNodeId(`${page.id}-book`);
20
20
  const slug = page.properties?.slug?.rich_text?.[0]?.plain_text || `unnamed-slug`;
21
- const bookCategoryId = page.properties?.category?.relation?.[0]?.id || null;
22
- const categoryNode = getNode(bookCategoryId);
21
+ const categoryId = page.properties?.category?.relation?.[0]?.id || null;
22
+ const book_category = createNodeId(`${categoryId}-category`);
23
23
  const bookNode = {
24
24
  id: nodeId,
25
25
  book_name: page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`,
@@ -36,7 +36,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, ge
36
36
  create_date: page.created_time,
37
37
  update_date: page.last_edited_time,
38
38
  url: `${constants_1.COMMON_URI}/${constants_1.BOOK_URI}/${slug}`,
39
- book_category: categoryNode,
39
+ book_category: book_category,
40
40
  };
41
41
  reporter.info(`[DEBUG] Book ${bookNode.book_name} has book_category: ${bookNode.book_category}`);
42
42
  createNode(bookNode);
@@ -40,6 +40,17 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
40
40
  }
41
41
  const nodeId = createNodeId(`${categoryJsonData.id}-category`);
42
42
  const categoryUrl = `${parentCategoryUrl}/${slug}`;
43
+ // Find Book
44
+ const bookRelations = page.properties?.books?.relation || null;
45
+ const books = [];
46
+ if (bookRelations) {
47
+ bookRelations.forEach((relation) => {
48
+ const bookId = relation.id;
49
+ const bookNodeId = createNodeId(`${bookId}-book`);
50
+ const bookNode = getNode(bookNodeId);
51
+ books.push(bookNode);
52
+ });
53
+ }
43
54
  const categoryNode = {
44
55
  id: nodeId,
45
56
  category_name: title,
@@ -54,7 +65,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
54
65
  .digest(`hex`),
55
66
  },
56
67
  url: `${constants_1.COMMON_URI}/${constants_1.CATEGORY_URI}${categoryUrl}`,
57
- books: [],
68
+ books: books,
58
69
  };
59
70
  await createNode(categoryNode);
60
71
  if (parentCategoryId && categoryNode) {
@@ -13,6 +13,13 @@ const sourceNodes = async (gatsbyApi, options) => {
13
13
  }
14
14
  reporter.info(`[INFO] Fetching pages from Notion database...`);
15
15
  try {
16
+ await (0, getBooks_1.getBooks)({
17
+ bookDatabaseId,
18
+ reporter,
19
+ createNode,
20
+ createNodeId,
21
+ getNode,
22
+ });
16
23
  await (0, getPages_1.getPages)({
17
24
  token,
18
25
  databaseId,
@@ -24,13 +31,6 @@ const sourceNodes = async (gatsbyApi, options) => {
24
31
  createParentChildLink,
25
32
  getNode,
26
33
  });
27
- await (0, getBooks_1.getBooks)({
28
- bookDatabaseId,
29
- reporter,
30
- createNode,
31
- createNodeId,
32
- getNode,
33
- });
34
34
  }
35
35
  catch (e) {
36
36
  reporter.error(`[ERROR] ${e}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatsby-source-notion-churnotion",
3
3
  "description": "Gatsby plugin that can connect with One Notion Database RECURSIVELY using official API",
4
- "version": "1.0.36",
4
+ "version": "1.0.38",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",