gatsby-source-notion-churnotion 1.1.38 → 1.1.40
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.
@@ -1,5 +1,8 @@
|
|
1
1
|
import { Reporter } from "gatsby";
|
2
2
|
import { BaseContentBlock } from "notion-types";
|
3
|
+
interface NotionBlock extends BaseContentBlock {
|
4
|
+
has_children?: boolean;
|
5
|
+
}
|
3
6
|
export interface NotionServiceOptions {
|
4
7
|
reporter: Reporter;
|
5
8
|
parallelLimit?: number;
|
@@ -17,14 +20,18 @@ export declare class NotionService {
|
|
17
20
|
*/
|
18
21
|
queryDatabase(databaseId: string, body?: any): Promise<any>;
|
19
22
|
/**
|
20
|
-
* 페이지의 자식 블록 가져오기
|
23
|
+
* 페이지의 자식 블록 가져오기 (재귀적 처리)
|
24
|
+
*/
|
25
|
+
getPageBlocks(pageId: string): Promise<NotionBlock[]>;
|
26
|
+
/**
|
27
|
+
* has_children이 true인 블록들의 자식을 재귀적으로 가져옴
|
21
28
|
*/
|
22
|
-
|
29
|
+
private fetchChildBlocks;
|
23
30
|
/**
|
24
31
|
* 여러 페이지의 블록 병렬 처리
|
25
32
|
*/
|
26
33
|
getMultiplePagesBlocks(pageIds: string[]): Promise<{
|
27
|
-
[id: string]:
|
34
|
+
[id: string]: NotionBlock[];
|
28
35
|
}>;
|
29
36
|
/**
|
30
37
|
* 캐시 초기화
|
@@ -35,3 +42,4 @@ export declare class NotionService {
|
|
35
42
|
*/
|
36
43
|
setParallelLimit(limit: number): void;
|
37
44
|
}
|
45
|
+
export {};
|
@@ -84,7 +84,7 @@ class NotionService {
|
|
84
84
|
}
|
85
85
|
}
|
86
86
|
/**
|
87
|
-
* 페이지의 자식 블록 가져오기
|
87
|
+
* 페이지의 자식 블록 가져오기 (재귀적 처리)
|
88
88
|
*/
|
89
89
|
async getPageBlocks(pageId) {
|
90
90
|
const cacheKey = `page-blocks-${pageId}`;
|
@@ -96,16 +96,46 @@ class NotionService {
|
|
96
96
|
try {
|
97
97
|
const data = await (0, fetchData_1.fetchGetWithRetry)(pageUrl);
|
98
98
|
const blocks = data.results;
|
99
|
+
// 재귀적으로 has_children이 true인 블록의 자식들을 가져옴
|
100
|
+
const blocksWithChildren = await this.fetchChildBlocks(blocks);
|
99
101
|
if (this.enableCaching) {
|
100
|
-
this.cache.set(cacheKey,
|
102
|
+
this.cache.set(cacheKey, blocksWithChildren);
|
101
103
|
}
|
102
|
-
return
|
104
|
+
return blocksWithChildren;
|
103
105
|
}
|
104
106
|
catch (error) {
|
105
107
|
this.reporter.error(`[ERROR] Failed to get page blocks ${pageId}: ${error}`);
|
106
108
|
throw error;
|
107
109
|
}
|
108
110
|
}
|
111
|
+
/**
|
112
|
+
* has_children이 true인 블록들의 자식을 재귀적으로 가져옴
|
113
|
+
*/
|
114
|
+
async fetchChildBlocks(blocks) {
|
115
|
+
if (!blocks || blocks.length === 0)
|
116
|
+
return blocks;
|
117
|
+
const tasks = blocks.map(async (block) => {
|
118
|
+
if (block.has_children) {
|
119
|
+
try {
|
120
|
+
this.reporter.info(`[NOTION] Fetching children for block ${block.id} of type ${block.type}`);
|
121
|
+
const childBlocks = await this.getPageBlocks(block.id);
|
122
|
+
// 자식 블록을 부모 블록에 추가
|
123
|
+
block.children = childBlocks;
|
124
|
+
// 특별히 table 타입의 경우 row 정보 추가
|
125
|
+
if (block.type === "table") {
|
126
|
+
block.table.rows = childBlocks;
|
127
|
+
}
|
128
|
+
return block;
|
129
|
+
}
|
130
|
+
catch (error) {
|
131
|
+
this.reporter.warn(`[WARNING] Failed to fetch children for block ${block.id}: ${error}`);
|
132
|
+
return block;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return block;
|
136
|
+
});
|
137
|
+
return Promise.all(tasks);
|
138
|
+
}
|
109
139
|
/**
|
110
140
|
* 여러 페이지의 블록 병렬 처리
|
111
141
|
*/
|
@@ -149,10 +149,6 @@ const createSchemaCustomization = ({ actions, schema }) => {
|
|
149
149
|
url: String!
|
150
150
|
}
|
151
151
|
|
152
|
-
type Fields {
|
153
|
-
childrenChurnotion: [${constants_1.NODE_TYPE.Post}] @link(by: "id")
|
154
|
-
}
|
155
|
-
|
156
152
|
type ${constants_1.NODE_TYPE.Metadata} implements Node {
|
157
153
|
id: ID!,
|
158
154
|
title: String,
|
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.1.
|
4
|
+
"version": "1.1.40",
|
5
5
|
"skipLibCheck": true,
|
6
6
|
"license": "0BSD",
|
7
7
|
"main": "./dist/gatsby-node.js",
|