gatsby-source-notion-churnotion 1.0.8 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ import { IGetBooksParams } from "../types";
2
+ export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, }: IGetBooksParams) => Promise<void>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getBooks = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const constants_1 = require("../constants");
9
+ const fetchData_1 = require("../util/fetchData");
10
+ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, }) => {
11
+ const databaseUrl = `databases/${bookDatabaseId}/query`;
12
+ const body = {};
13
+ const result = await (0, fetchData_1.fetchPostWithRetry)(databaseUrl, body);
14
+ if (result?.results?.length) {
15
+ reporter.info(`[SUCCESS] total BOOK pages > ${result.results.length}`);
16
+ }
17
+ for (const page of result.results) {
18
+ reporter.info(`[CHECK] BOOK page: ${page.id}`);
19
+ const nodeId = createNodeId(`${page.id}-book`);
20
+ const bookNode = {
21
+ id: nodeId,
22
+ book_name: page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`,
23
+ slug: page.properties?.slug?.rich_text?.plain_text || `unnamed-slug`,
24
+ parent: null,
25
+ children: [],
26
+ internal: {
27
+ type: constants_1.NODE_TYPE.Category,
28
+ contentDigest: crypto_1.default
29
+ .createHash(`md5`)
30
+ .update(JSON.stringify(page))
31
+ .digest(`hex`),
32
+ },
33
+ create_date: page.created_time,
34
+ update_date: page.last_edited_time,
35
+ };
36
+ createNode(bookNode);
37
+ }
38
+ };
39
+ exports.getBooks = getBooks;
@@ -27,7 +27,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
27
27
  reporter.info(`[SUCCESS] total pages > ${result.results.length}`);
28
28
  }
29
29
  for (const page of result.results) {
30
- reporter.info(`[CHECK!!!] page: ${page.id}`);
30
+ reporter.info(`[CHECK] page: ${page.id}`);
31
31
  const pageUrl = `blocks/${page.id}/children?page_size=100`;
32
32
  // 페이지 데이터
33
33
  const pageData = await (0, fetchData_1.fetchGetWithRetry)(pageUrl);
@@ -122,12 +122,13 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
122
122
  const postNode = {
123
123
  id: nodeId,
124
124
  category: parentCategoryId,
125
- book_id: bookId,
125
+ book: getNode(`${bookId}-book`),
126
+ book_index: page.properties?.bookIndex?.number || 0,
126
127
  title: title,
127
128
  content: markdownContent,
128
129
  create_date: page.created_time,
129
130
  update_date: page.last_edited_time,
130
- version: page.properties?.version?.rich_text?.[0]?.plain_text || null,
131
+ version: page.properties?.version?.number || null,
131
132
  description: null,
132
133
  slug: slug || `no-title-${nodeId}`,
133
134
  category_list: categoryPath,
@@ -143,7 +144,15 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
143
144
  parent: null,
144
145
  };
145
146
  await createNode(postNode);
146
- // tag와 post 부모-자식 관계 설정정
147
+ // book과 post 부모-자식 관계 설정
148
+ const bookNode = getNode(bookId);
149
+ if (bookNode) {
150
+ createParentChildLink({
151
+ parent: bookNode,
152
+ child: postNode,
153
+ });
154
+ }
155
+ // tag와 post 부모-자식 관계 설정
147
156
  tagIds.forEach((tagId) => {
148
157
  const tagNode = getNode(tagId);
149
158
  if (tagNode) {
@@ -9,7 +9,8 @@ const createSchemaCustomization = ({ actions }) => {
9
9
  id: ID!
10
10
  category: ${constants_1.NODE_TYPE.Category}! @link(by: "id", from: "category")
11
11
  tags: [${constants_1.NODE_TYPE.Tag}] @link(by: "id")
12
- book_id: ${constants_1.NODE_TYPE.Book} @link(by: "id")
12
+ book: ${constants_1.NODE_TYPE.Book} @link(by: "id")
13
+ book_index: Int
13
14
  title: String
14
15
  content: [JSON]
15
16
  create_date: Date! @dateformat
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sourceNodes = void 0;
4
- const getPage_1 = require("./api/getPage");
4
+ const getPages_1 = require("./api/getPages");
5
+ const getBooks_1 = require("./api/getBooks");
5
6
  const sourceNodes = async (gatsbyApi, options) => {
6
7
  const { actions, reporter, createNodeId, getNode, getCache } = gatsbyApi;
7
8
  const { createNode, createParentChildLink } = actions;
8
- const { token, databaseId } = options;
9
+ const { token, databaseId, bookDatabaseId } = options;
9
10
  if (!token || !databaseId) {
10
11
  reporter.error(`[ERROR] Missing Notion API token or database ID.`);
11
12
  return;
12
13
  }
13
14
  reporter.info(`[INFO] Fetching pages from Notion database...`);
14
15
  try {
15
- await (0, getPage_1.getPages)({
16
+ await (0, getBooks_1.getBooks)({
17
+ bookDatabaseId,
18
+ reporter,
19
+ createNode,
20
+ createNodeId,
21
+ });
22
+ await (0, getPages_1.getPages)({
16
23
  token,
17
24
  databaseId,
18
25
  reporter,
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.8",
4
+ "version": "1.0.10",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",
File without changes