gatsby-source-notion-churnotion 1.0.83 → 1.0.85
Sign up to get free protection for your applications and to get access to all the features.
package/dist/api/getBooks.js
CHANGED
@@ -8,6 +8,7 @@ const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const constants_1 = require("../constants");
|
9
9
|
const fetchData_1 = require("../util/fetchData");
|
10
10
|
const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
|
11
|
+
const bookCategoryMap_1 = __importDefault(require("../util/bookCategoryMap"));
|
11
12
|
const getBooks = async ({ bookDatabaseId, reporter, getCache, createNode, createNodeId, getNode, cache, }) => {
|
12
13
|
const databaseUrl = `databases/${bookDatabaseId}/query`;
|
13
14
|
const cacheKey = `booksDatabase-${bookDatabaseId}`;
|
@@ -32,7 +33,12 @@ const getBooks = async ({ bookDatabaseId, reporter, getCache, createNode, create
|
|
32
33
|
const categoryId = page.properties?.category?.relation?.[0]?.id || null;
|
33
34
|
let book_category = null;
|
34
35
|
if (categoryId) {
|
35
|
-
|
36
|
+
const bookCategoryId = createNodeId(`${categoryId}-category`);
|
37
|
+
book_category = bookCategoryId;
|
38
|
+
if (!bookCategoryMap_1.default.has(bookCategoryId)) {
|
39
|
+
bookCategoryMap_1.default.set(bookCategoryId, []);
|
40
|
+
}
|
41
|
+
bookCategoryMap_1.default.get(bookCategoryId).push(nodeId);
|
36
42
|
}
|
37
43
|
const bookImage = page.properties?.bookImage?.files?.[0]?.file.url;
|
38
44
|
const bookImageNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
|
package/dist/api/getPages.js
CHANGED
@@ -9,6 +9,7 @@ const constants_1 = require("../constants");
|
|
9
9
|
const fetchData_1 = require("../util/fetchData");
|
10
10
|
const processor_1 = require("../util/processor");
|
11
11
|
const slugify_1 = require("../util/slugify");
|
12
|
+
const bookCategoryMap_1 = __importDefault(require("../util/bookCategoryMap"));
|
12
13
|
const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, cache, }) => {
|
13
14
|
/**
|
14
15
|
* 데이터베이스 내에 페이지들을 읽어서 재귀적으로 추가하는 서브 메서드드
|
@@ -66,6 +67,18 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
|
|
66
67
|
parent: categoryNode,
|
67
68
|
child: bookNode,
|
68
69
|
});
|
70
|
+
const updatedBookNode = {
|
71
|
+
...bookNode,
|
72
|
+
book_category: categoryNode.id,
|
73
|
+
internal: {
|
74
|
+
...bookNode.internal,
|
75
|
+
contentDigest: crypto_1.default
|
76
|
+
.createHash(`md5`)
|
77
|
+
.update(JSON.stringify(bookNode))
|
78
|
+
.digest(`hex`),
|
79
|
+
},
|
80
|
+
};
|
81
|
+
createNode(updatedBookNode);
|
69
82
|
reporter.info(`[SUCCESS] Linked Category-Book: ${categoryNode.category_name} -> child: ${bookNode.book_name}`);
|
70
83
|
}
|
71
84
|
});
|
@@ -217,5 +230,39 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
|
|
217
230
|
}
|
218
231
|
};
|
219
232
|
await processDatabase(databaseId);
|
233
|
+
// Category - Book Relation Update
|
234
|
+
for (const [categoryId, bookIds] of bookCategoryMap_1.default.entries()) {
|
235
|
+
const categoryNode = getNode(categoryId);
|
236
|
+
if (categoryNode) {
|
237
|
+
for (const bookId of bookIds) {
|
238
|
+
const bookNode = getNode(bookId);
|
239
|
+
if (bookNode) {
|
240
|
+
createParentChildLink({
|
241
|
+
parent: categoryNode,
|
242
|
+
child: bookNode,
|
243
|
+
});
|
244
|
+
const updatedBookNode = {
|
245
|
+
...bookNode,
|
246
|
+
book_category: categoryNode.id,
|
247
|
+
internal: {
|
248
|
+
...bookNode.internal,
|
249
|
+
contentDigest: crypto_1.default
|
250
|
+
.createHash(`md5`)
|
251
|
+
.update(JSON.stringify(bookNode))
|
252
|
+
.digest(`hex`),
|
253
|
+
},
|
254
|
+
};
|
255
|
+
createNode(updatedBookNode);
|
256
|
+
reporter.info(`[SUCCESS] Linked Book to Category: ${bookNode.book_name} -> ${categoryNode.category_name}`);
|
257
|
+
}
|
258
|
+
else {
|
259
|
+
reporter.warn(`[WARNING] Book node not found: ${bookId}`);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
else {
|
264
|
+
reporter.warn(`[WARNING] Category node not found: ${categoryId}`);
|
265
|
+
}
|
266
|
+
}
|
220
267
|
};
|
221
268
|
exports.getPages = getPages;
|
@@ -42,7 +42,7 @@ const createSchemaCustomization = ({ actions }) => {
|
|
42
42
|
children: [${constants_1.NODE_TYPE.Category}!]! @link(by: "parent")
|
43
43
|
churnotions: [${constants_1.NODE_TYPE.Post}] @link(by: "category", from: "id")
|
44
44
|
url: String!
|
45
|
-
books: [${constants_1.NODE_TYPE.Book}] @link(by: "id"
|
45
|
+
books: [${constants_1.NODE_TYPE.Book}] @link(by: "id")
|
46
46
|
}
|
47
47
|
|
48
48
|
type ${constants_1.NODE_TYPE.Book} implements Node {
|
@@ -52,7 +52,7 @@ const createSchemaCustomization = ({ actions }) => {
|
|
52
52
|
update_date: Date! @dateformat
|
53
53
|
children: [${constants_1.NODE_TYPE.Post}] @link(by: "book", from: "id")
|
54
54
|
url: String!
|
55
|
-
book_category: ${constants_1.NODE_TYPE.Category} @link(by: "id")
|
55
|
+
book_category: ${constants_1.NODE_TYPE.Category} @link(by: "id", from: "books")
|
56
56
|
book_image: File @link(by: "id", from: "book_image")
|
57
57
|
}
|
58
58
|
|
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.
|
4
|
+
"version": "1.0.85",
|
5
5
|
"skipLibCheck": true,
|
6
6
|
"license": "0BSD",
|
7
7
|
"main": "./dist/gatsby-node.js",
|