gatsby-source-notion-churnotion 1.0.45 → 1.0.47

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,6 @@ const constants_1 = require("../constants");
9
9
  const fetchData_1 = require("../util/fetchData");
10
10
  const imageProcessor_1 = require("../util/imageProcessor");
11
11
  const slugify_1 = require("../util/slugify");
12
- const connector_1 = require("./connector");
13
12
  const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, }) => {
14
13
  /**
15
14
  * 데이터베이스 내에 페이지들을 읽어서 재귀적으로 추가하는 서브 메서드드
@@ -141,22 +140,14 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
141
140
  });
142
141
  }
143
142
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
144
- const markdownContent = await connector_1.n2m.pageToMarkdown(page.id);
145
- const imageNode = await (0, imageProcessor_1.processBlocks)(markdownContent, actions, getCache, createNodeId, reporter, createParentChildLink);
146
- const gatsbyImageData = {
147
- childImageSharp: {
148
- gatsbyImageData: imageNode
149
- ? `childImageSharp___NODE___${imageNode}`
150
- : null,
151
- },
152
- };
143
+ const imageNode = await (0, imageProcessor_1.processBlocks)(pageData.results, actions, getCache, createNodeId, reporter);
153
144
  const postNode = {
154
145
  id: nodeId,
155
146
  category: parentCategoryId,
156
147
  book: getNode(`${bookId}-book`),
157
148
  book_index: page.properties?.bookIndex?.number || 0,
158
149
  title: title,
159
- content: markdownContent,
150
+ content: pageData.results,
160
151
  create_date: page.created_time,
161
152
  update_date: page.last_edited_time,
162
153
  version: page.properties?.version?.number || null,
@@ -1,3 +1,3 @@
1
1
  import { Actions, GatsbyCache, Reporter } from "gatsby";
2
- import { MdBlock } from "notion-to-md/build/types";
3
- export declare const processBlocks: (blocks: MdBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter, createParentChildLink: any) => Promise<string | null>;
2
+ import { BaseContentBlock } from "notion-types";
3
+ export declare const processBlocks: (blocks: BaseContentBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter) => Promise<string | null>;
@@ -2,43 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processBlocks = void 0;
4
4
  const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
5
- const processBlocks = async (blocks, actions, getCache, createNodeId, reporter, createParentChildLink) => {
5
+ // Type Guard
6
+ function isImageBlock(block) {
7
+ return block.type === "image" && "image" in block;
8
+ }
9
+ const processBlocks = async (blocks, actions, getCache, createNodeId, reporter) => {
6
10
  const { createNode } = actions;
7
11
  let thumbnail = null;
8
12
  for (const block of blocks) {
9
- const blockNodeId = createNodeId(`${block.blockId}-MdBlock`);
10
- const blockNode = {
11
- ...block,
12
- id: blockNodeId,
13
- parent: null,
14
- children: [],
15
- internal: {
16
- type: "MdBlock",
17
- contentDigest: createNodeId(JSON.stringify(block)),
18
- },
19
- };
20
- createNode(blockNode);
21
- if (block.type === `image` &&
22
- typeof block.parent === `string` &&
23
- block.parent.includes(`http`)) {
24
- const match = block.parent.match(/\((https?:\/\/.*?)\)/);
13
+ if (isImageBlock(block) && block?.image?.file?.url) {
14
+ const match = block.image.file.url.match(/\((https?:\/\/.*?)\)/);
25
15
  if (match) {
26
16
  const imageUrl = match[1];
27
17
  reporter.info(`[Image] got image > ${imageUrl}`);
28
18
  try {
29
19
  const fileNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
30
20
  url: imageUrl,
31
- parentNodeId: blockNodeId,
21
+ parentNodeId: block.id,
32
22
  getCache,
33
23
  createNode,
34
24
  createNodeId,
35
25
  });
36
26
  if (fileNode) {
37
- createParentChildLink({
38
- parent: blockNode,
39
- child: fileNode,
40
- });
41
- block.parent = fileNode.id;
42
27
  if (!thumbnail)
43
28
  thumbnail = fileNode.id;
44
29
  reporter.info(`[SUCCESS] Image processed: ${fileNode.id}`);
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.45",
4
+ "version": "1.0.47",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",
@@ -42,6 +42,7 @@
42
42
  "gatsby-transformer-sharp": "^5.14.0",
43
43
  "node-fetch": "^3.3.2",
44
44
  "notion-to-md": "^3.1.1",
45
+ "notion-types": "^7.1.5",
45
46
  "typescript": "^5.7.2"
46
47
  },
47
48
  "devDependencies": {