gatsby-source-notion-churnotion 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,11 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, })
17
17
  for (const page of result.results) {
18
18
  reporter.info(`[CHECK] BOOK page: ${page.id}`);
19
19
  const nodeId = createNodeId(`${page.id}-book`);
20
+ const slug = page.properties?.slug?.rich_text?.[0]?.plain_text || `unnamed-slug`;
20
21
  const bookNode = {
21
22
  id: nodeId,
22
23
  book_name: page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`,
23
- slug: page.properties?.slug?.rich_text?.plain_text || `unnamed-slug`,
24
+ slug: slug,
24
25
  parent: null,
25
26
  children: [],
26
27
  internal: {
@@ -32,6 +33,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, })
32
33
  },
33
34
  create_date: page.created_time,
34
35
  update_date: page.last_edited_time,
36
+ url: `${constants_1.COMMON_URI}/${constants_1.BOOK_URI}/${slug}`,
35
37
  };
36
38
  createNode(bookNode);
37
39
  }
@@ -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, categoryPath = [], tagMap = {}) => {
20
+ const processDatabase = async (databaseId, parentCategoryId = null, categoryPath = [], tagMap = {}, categoryUrl = ``) => {
21
21
  try {
22
22
  while (hasMore) {
23
23
  const databaseUrl = `databases/${databaseId}/query`;
@@ -34,16 +34,17 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
34
34
  if (pageData.results[0].type === `child_database`) {
35
35
  const categoryJsonData = pageData.results[0];
36
36
  const title = categoryJsonData.child_database?.title || `Unnamed Category`;
37
- const slug = (0, slugify_1.slugify)(title);
37
+ const slug = (0, slugify_1.slugify)(title) || `no-title-${categoryJsonData.id}`;
38
38
  if (!title) {
39
39
  reporter.warn(`[WARNING] Category without a title detected: ${categoryJsonData.id}`);
40
40
  }
41
41
  const nodeId = createNodeId(`${categoryJsonData.id}-category`);
42
+ categoryUrl += `${categoryUrl.length === 0 ? "" : "/"}${slug}`;
42
43
  const categoryNode = {
43
44
  id: nodeId,
44
45
  category_name: title,
45
46
  parent: parentCategoryId,
46
- slug: slug || `no-title-${categoryJsonData.id}`,
47
+ slug: slug,
47
48
  children: [],
48
49
  internal: {
49
50
  type: constants_1.NODE_TYPE.Category,
@@ -52,6 +53,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
52
53
  .update(JSON.stringify(categoryJsonData))
53
54
  .digest(`hex`),
54
55
  },
56
+ url: `${constants_1.COMMON_URI}/${constants_1.CATEGORY_URI}/${categoryUrl}`,
55
57
  };
56
58
  createNode(categoryNode);
57
59
  if (parentCategoryId && categoryNode) {
@@ -68,7 +70,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
68
70
  }
69
71
  }
70
72
  const newCategoryPath = [...categoryPath, categoryNode];
71
- await processDatabase(categoryJsonData.id, nodeId, newCategoryPath, tagMap);
73
+ await processDatabase(categoryJsonData.id, nodeId, newCategoryPath, tagMap, categoryUrl);
72
74
  }
73
75
  else {
74
76
  // 페이지인 경우
@@ -97,10 +99,12 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
97
99
  const tagNodeId = createNodeId(`${tagData.id}-tag`);
98
100
  tagMap[tagData.name] = tagNodeId; // tagMap에 저장
99
101
  tagIds.push(tagNodeId); // 새로운 태그 ID 추가
102
+ const slug = (0, slugify_1.slugify)(tagData.name) || `no-tag-${tagNodeId}`;
100
103
  // 태그 노드 생성
101
104
  const tagNode = {
102
105
  id: tagNodeId,
103
106
  tag_name: tagData.name,
107
+ slug: slug,
104
108
  color: tagData.color,
105
109
  children: [],
106
110
  internal: {
@@ -110,6 +114,9 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
110
114
  .update(JSON.stringify(tagData))
111
115
  .digest(`hex`),
112
116
  },
117
+ url: `${constants_1.COMMON_URI}/${constants_1.TAG_URI}/${slug}`,
118
+ churnotions: [],
119
+ parent: null,
113
120
  };
114
121
  createNode(tagNode);
115
122
  reporter.info(`[SUCCESS] Created new tag: ${tagData.name}`);
@@ -130,7 +137,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
130
137
  update_date: page.last_edited_time,
131
138
  version: page.properties?.version?.number || null,
132
139
  description: null,
133
- slug: slug || `no-title-${nodeId}`,
140
+ slug: slug,
134
141
  category_list: categoryPath,
135
142
  children: [],
136
143
  internal: {
@@ -142,6 +149,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
142
149
  },
143
150
  tags: tagIds,
144
151
  parent: null,
152
+ url: `${categoryUrl.length === 0 ? "" : "/"}/${categoryUrl}/${slug}`,
145
153
  };
146
154
  await createNode(postNode);
147
155
  // book과 post 부모-자식 관계 설정
@@ -7,3 +7,8 @@ export declare const NODE_TYPE: {
7
7
  Tag: string;
8
8
  Book: string;
9
9
  };
10
+ export declare const COMMON_URI = "blog";
11
+ export declare const POST_URI = "post";
12
+ export declare const BOOK_URI = "book";
13
+ export declare const TAG_URI = "tag";
14
+ export declare const CATEGORY_URI = "category";
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NODE_TYPE = exports.PLUGIN_NAME = exports.NOTION_LIMIT_ERROR = exports.NOTION_API_VERSION = void 0;
3
+ exports.CATEGORY_URI = exports.TAG_URI = exports.BOOK_URI = exports.POST_URI = exports.COMMON_URI = exports.NODE_TYPE = exports.PLUGIN_NAME = exports.NOTION_LIMIT_ERROR = exports.NOTION_API_VERSION = void 0;
4
4
  exports.NOTION_API_VERSION = `2022-06-28`;
5
5
  exports.NOTION_LIMIT_ERROR = 429;
6
6
  exports.PLUGIN_NAME = `gatsby-source-notion-churnotion`;
@@ -11,3 +11,9 @@ exports.NODE_TYPE = {
11
11
  Tag: `NTag`,
12
12
  Book: `NBook`,
13
13
  };
14
+ ///////////////url resource///////////////////////
15
+ exports.COMMON_URI = `blog`;
16
+ exports.POST_URI = `post`;
17
+ exports.BOOK_URI = `book`;
18
+ exports.TAG_URI = `tag`;
19
+ exports.CATEGORY_URI = `category`;
@@ -19,13 +19,16 @@ const createSchemaCustomization = ({ actions }) => {
19
19
  description: String
20
20
  slug: String
21
21
  category_list: [${constants_1.NODE_TYPE.Category}]
22
+ url: String!
22
23
  }
23
24
 
24
25
  type ${constants_1.NODE_TYPE.Tag} implements Node {
25
26
  id: ID!
26
27
  tag_name: String!
28
+ slug: String!
27
29
  color: String!
28
30
  children: [${constants_1.NODE_TYPE.Post}] @link(by: "id", from: "tags")
31
+ url: String!
29
32
  }
30
33
 
31
34
  type ${constants_1.NODE_TYPE.Category} implements Node {
@@ -35,6 +38,7 @@ const createSchemaCustomization = ({ actions }) => {
35
38
  slug: String!
36
39
  children: [${constants_1.NODE_TYPE.Category}!]! @link(by: "parent")
37
40
  churnotions: [${constants_1.NODE_TYPE.Post}] @link(by: "book", from: "id")
41
+ url: String!
38
42
  }
39
43
 
40
44
  type ${constants_1.NODE_TYPE.Book} implements Node {
@@ -43,6 +47,7 @@ const createSchemaCustomization = ({ actions }) => {
43
47
  create_date: Date! @dateformat
44
48
  update_date: Date! @dateformat
45
49
  children: [${constants_1.NODE_TYPE.Post}] @link(by: "book", from: "id")
50
+ url: String!
46
51
  }
47
52
  `);
48
53
  };
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.13",
4
+ "version": "1.0.14",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",