gatsby-source-notion-churnotion 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
17
17
  * @param databaseId 데이터베이스 아이디
18
18
  * @param parentCategoryId 부모 데이터베이스 아이디
19
19
  */
20
- const processDatabase = async (databaseId, parentCategoryId = null) => {
20
+ const processDatabase = async (databaseId, parentCategoryId = null, categoryPath = []) => {
21
21
  try {
22
22
  while (hasMore) {
23
23
  const databaseUrl = `databases/${databaseId}/query`;
@@ -42,7 +42,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
42
42
  const categoryNode = {
43
43
  id: nodeId,
44
44
  category_name: title,
45
- parent_id: parentCategoryId,
45
+ parent: parentCategoryId,
46
46
  slug: slug || `no-title-${categoryJsonData.id}`,
47
47
  children: [],
48
48
  internal: {
@@ -67,12 +67,17 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
67
67
  reporter.warn(`[WARNING] Parent node not found for ID: ${parentCategoryId}`);
68
68
  }
69
69
  }
70
- await processDatabase(categoryJsonData.id, nodeId);
70
+ const newCategoryPath = [...categoryPath, categoryNode];
71
+ await processDatabase(categoryJsonData.id, nodeId, newCategoryPath);
71
72
  }
72
73
  else {
73
74
  // 페이지인 경우
74
75
  const title = page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`;
75
- const slug = (0, slugify_1.slugify)(title);
76
+ const slug = (0, slugify_1.slugify)(page.properties?.[`slug`]?.rich_text?.[0]?.plain_text ||
77
+ crypto_1.default
78
+ .createHash(`md5`)
79
+ .update(JSON.stringify(title))
80
+ .digest(`hex`));
76
81
  if (!title) {
77
82
  reporter.warn(`[WARNING] Category without a title detected: ${page.id}`);
78
83
  }
@@ -97,7 +102,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
97
102
  await (0, imageProcessor_1.processBlocks)(markdownContent, actions, getCache, createNodeId, reporter);
98
103
  const postNode = {
99
104
  id: nodeId,
100
- category_id: parentCategoryId,
105
+ category: parentCategoryId,
101
106
  book_id: bookId,
102
107
  title: title,
103
108
  content: markdownContent,
@@ -106,14 +111,18 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
106
111
  version: page.properties?.version?.rich_text?.[0]?.plain_text || null,
107
112
  description: null,
108
113
  slug: slug || `no-title-${nodeId}`,
114
+ category_list: categoryPath,
109
115
  children: [],
110
116
  internal: {
117
+ owner: "a",
111
118
  type: constants_1.NODE_TYPE.Post,
112
119
  contentDigest: crypto_1.default
113
120
  .createHash(`md5`)
114
121
  .update(JSON.stringify(nodeId))
115
122
  .digest(`hex`),
116
123
  },
124
+ tags: [],
125
+ parent: null,
117
126
  };
118
127
  await createNode(postNode);
119
128
  if (parentCategoryId && postNode) {
@@ -7,7 +7,7 @@ const createSchemaCustomization = ({ actions }) => {
7
7
  createTypes(`
8
8
  type ${constants_1.NODE_TYPE.Post} implements Node {
9
9
  id: ID!
10
- category_id: ${constants_1.NODE_TYPE.Category} @link(by: "id")
10
+ category: ${constants_1.NODE_TYPE.Category}! @link(by: "id", "category")
11
11
  tags: ${constants_1.NODE_TYPE.Tag} @link(by: "id")
12
12
  book_id: ${constants_1.NODE_TYPE.Book} @link(by: "id")
13
13
  title: String
@@ -17,6 +17,7 @@ const createSchemaCustomization = ({ actions }) => {
17
17
  version: Int
18
18
  description: String
19
19
  slug: String
20
+ category_list: [${constants_1.NODE_TYPE.Category}]
20
21
  }
21
22
 
22
23
  type ${constants_1.NODE_TYPE.Tag} implements Node {
@@ -27,9 +28,10 @@ const createSchemaCustomization = ({ actions }) => {
27
28
 
28
29
  type ${constants_1.NODE_TYPE.Category} implements Node {
29
30
  id: ID!
30
- parent_id: ${constants_1.NODE_TYPE.Category} @link(by: "id")
31
+ parent: ${constants_1.NODE_TYPE.Category} @link(by: "id", from: "parent")
31
32
  category_name: String!
32
33
  slug: String!
34
+ children: [${constants_1.NODE_TYPE.Category}!]! @link(by: "parent")
33
35
  }
34
36
 
35
37
  type ${constants_1.NODE_TYPE.Book} implements Node {
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.2",
4
+ "version": "1.0.4",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",