gatsby-source-notion-churnotion 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/dist/api/getPage.js +45 -17
  2. package/package.json +1 -1
@@ -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 = []) => {
20
+ const processDatabase = async (databaseId, parentCategoryId = null, categoryPath = [], tagMap = {}) => {
21
21
  try {
22
22
  while (hasMore) {
23
23
  const databaseUrl = `databases/${databaseId}/query`;
@@ -68,7 +68,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
68
68
  }
69
69
  }
70
70
  const newCategoryPath = [...categoryPath, categoryNode];
71
- await processDatabase(categoryJsonData.id, nodeId, newCategoryPath);
71
+ await processDatabase(categoryJsonData.id, nodeId, newCategoryPath, tagMap);
72
72
  }
73
73
  else {
74
74
  // 페이지인 경우
@@ -86,21 +86,34 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
86
86
  const tagIds = [];
87
87
  if (page.properties.tags && page.properties.tags.multi_select) {
88
88
  page.properties.tags.multi_select.forEach((tagData) => {
89
- const tagNodeId = createNodeId(`${tagData.id}-tag`);
90
- tagIds.push(tagNodeId); // 태그 ID 저장
91
- createNode({
92
- id: tagNodeId,
93
- tag_name: tagData.name,
94
- color: tagData.color,
95
- churnotions: [],
96
- internal: {
97
- type: constants_1.NODE_TYPE.Tag,
98
- contentDigest: crypto_1.default
99
- .createHash(`md5`)
100
- .update(JSON.stringify(tagData))
101
- .digest(`hex`),
102
- },
103
- });
89
+ if (tagMap[tagData.name]) {
90
+ // 이미 존재하는 태그라면 tagMap에서 가져오기
91
+ const existingTagId = tagMap[tagData.name];
92
+ tagIds.push(existingTagId); // 기존 태그 ID 추가
93
+ reporter.info(`[INFO] Reusing existing tag: ${tagData.name}`);
94
+ }
95
+ else {
96
+ // 새로운 태그 생성
97
+ const tagNodeId = createNodeId(`${tagData.id}-tag`);
98
+ tagMap[tagData.name] = tagNodeId; // tagMap에 저장
99
+ tagIds.push(tagNodeId); // 새로운 태그 ID 추가
100
+ // 태그 노드 생성
101
+ const tagNode = {
102
+ id: tagNodeId,
103
+ tag_name: tagData.name,
104
+ color: tagData.color,
105
+ churnotions: [], // 연결된 페이지 리스트 초기화
106
+ internal: {
107
+ type: constants_1.NODE_TYPE.Tag,
108
+ contentDigest: crypto_1.default
109
+ .createHash(`md5`)
110
+ .update(JSON.stringify(tagData))
111
+ .digest(`hex`),
112
+ },
113
+ };
114
+ createNode(tagNode);
115
+ reporter.info(`[SUCCESS] Created new tag: ${tagData.name}`);
116
+ }
104
117
  });
105
118
  }
106
119
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
@@ -130,6 +143,21 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
130
143
  parent: null,
131
144
  };
132
145
  await createNode(postNode);
146
+ // tag와 post 부모-자식 관계 설정정
147
+ tagIds.forEach((tagId) => {
148
+ const tagNode = getNode(tagId);
149
+ if (tagNode) {
150
+ createParentChildLink({
151
+ parent: tagNode,
152
+ child: postNode,
153
+ });
154
+ reporter.info(`[SUCCESS] Linked tag: ${tagNode.tag_name} -> page: ${postNode.title}`);
155
+ }
156
+ else {
157
+ reporter.warn(`[WARNING] Tag node not found for ID: ${tagId}`);
158
+ }
159
+ });
160
+ // category와 post 부모-자식 관계 설정
133
161
  if (parentCategoryId && postNode) {
134
162
  const parentNode = getNode(parentCategoryId); // Gatsby에서 노드를 검색
135
163
  if (parentNode) {
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.7",
4
+ "version": "1.0.8",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",