gatsby-source-notion-churnotion 1.0.19 → 1.0.21

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.
@@ -125,7 +125,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
125
125
  }
126
126
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
127
127
  const markdownContent = await connector_1.n2m.pageToMarkdown(page.id);
128
- await (0, imageProcessor_1.processBlocks)(markdownContent, actions, getCache, createNodeId, reporter);
128
+ const thumbnailUrl = await (0, imageProcessor_1.processBlocks)(markdownContent, actions, getCache, createNodeId, reporter);
129
129
  const postNode = {
130
130
  id: nodeId,
131
131
  category: parentCategoryId,
@@ -150,6 +150,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
150
150
  tags: tagIds,
151
151
  parent: null,
152
152
  url: `${constants_1.COMMON_URI}/${constants_1.POST_URI}${categoryUrl}/${slug}`,
153
+ thumbnailUrl: thumbnailUrl,
153
154
  };
154
155
  await createNode(postNode);
155
156
  // book과 post 부모-자식 관계 설정
@@ -20,6 +20,7 @@ const createSchemaCustomization = ({ actions }) => {
20
20
  slug: String
21
21
  category_list: [${constants_1.NODE_TYPE.Category}]
22
22
  url: String!
23
+ thumbnailUrl: String
23
24
  }
24
25
 
25
26
  type ${constants_1.NODE_TYPE.Tag} implements Node {
@@ -1,3 +1,3 @@
1
1
  import { Actions, GatsbyCache, Reporter } from "gatsby";
2
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) => Promise<void>;
3
+ export declare const processBlocks: (blocks: MdBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter) => Promise<string>;
@@ -6,34 +6,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.processBlocks = void 0;
7
7
  const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
8
8
  const path_1 = __importDefault(require("path"));
9
- const crypto_1 = __importDefault(require("crypto"));
10
9
  const processBlocks = async (blocks, actions, getCache, createNodeId, reporter) => {
11
10
  const { createNode } = actions;
11
+ let thumbnailUrl = ``;
12
12
  for (const block of blocks) {
13
- // 이미지 블록 처리
13
+ // Process image blocks
14
14
  if (block.type === `image` &&
15
15
  typeof block.parent === `string` &&
16
16
  block.parent.includes(`http`)) {
17
- const match = block.parent.match(/\((https?:\/\/.*\.(?:png|jpg|jpeg|gif|webp))\)/);
17
+ const match = block.parent.match(/\((https?:\/\/.*?)\)/); // Extract URL inside parentheses
18
18
  if (match) {
19
- const imageUrl = match[1]; // 이미지 URL 추출
19
+ const imageUrl = match[1]; // Full image URL
20
20
  try {
21
- // 해싱된 파일명 생성
22
- const fileExtension = path_1.default.extname(imageUrl); // 확장자 추출
23
- const hashedFileName = crypto_1.default.createHash(`md5`).update(imageUrl).digest(`hex`) +
24
- fileExtension;
25
- // 파일 생성
21
+ // Extract file extension
22
+ const urlWithoutQuery = imageUrl.split("?")[0]; // Remove query parameters
23
+ const fileExtension = path_1.default.extname(urlWithoutQuery); // Extract extension
24
+ // const hashedFileName =
25
+ // crypto.createHash(`md5`).update(imageUrl).digest(`hex`) +
26
+ // fileExtension;
27
+ // Create the file node
26
28
  const fileNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
27
29
  url: imageUrl,
28
- parentNodeId: block.blockId, // 블록 ID 부모로 설정
30
+ parentNodeId: block.blockId, // Set block ID as parent
29
31
  getCache,
30
32
  createNode,
31
33
  createNodeId,
32
- name: hashedFileName,
33
34
  });
34
35
  if (fileNode) {
35
- const relativePath = `/static/images/${hashedFileName}`; // 해싱된 파일명을 사용
36
- block.parent = `![${hashedFileName}](${relativePath})`; // Markdown 형식으로 업데이트
36
+ const relativePath = fileNode.relativePath; // Use hashed file name
37
+ block.parent = block.parent.replace(/\(https?:\/\/.*?\)/, `(${relativePath})`); // Update Markdown syntax
38
+ if (thumbnailUrl.length === 0)
39
+ thumbnailUrl = relativePath;
37
40
  reporter.info(`[SUCCESS] Updated block with new hashed image path: ${block.parent}`);
38
41
  }
39
42
  }
@@ -43,5 +46,6 @@ const processBlocks = async (blocks, actions, getCache, createNodeId, reporter)
43
46
  }
44
47
  }
45
48
  }
49
+ return thumbnailUrl;
46
50
  };
47
51
  exports.processBlocks = processBlocks;
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.19",
4
+ "version": "1.0.21",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",