gatsby-source-notion-churnotion 1.0.62 → 1.0.64

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.
@@ -7,10 +7,8 @@ exports.getPages = void 0;
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const constants_1 = require("../constants");
9
9
  const fetchData_1 = require("../util/fetchData");
10
- const imageProcessor_1 = require("../util/imageProcessor");
11
10
  const slugify_1 = require("../util/slugify");
12
- const tableOfContent_1 = require("../util/tableOfContent");
13
- const metadataProcessor_1 = require("../util/metadataProcessor");
11
+ const processor_1 = require("../util/processor");
14
12
  const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, }) => {
15
13
  /**
16
14
  * 데이터베이스 내에 페이지들을 읽어서 재귀적으로 추가하는 서브 메서드드
@@ -141,9 +139,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
141
139
  });
142
140
  }
143
141
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
144
- const imageNode = await (0, imageProcessor_1.processBlocks)(pageData.results, actions, getCache, createNodeId, reporter);
145
- const tableOfContents = await (0, tableOfContent_1.processTableOfContents)(pageData.results, actions, getCache, createNodeId, reporter);
146
- const blocksWithMetadata = await (0, metadataProcessor_1.processMetadata)(pageData.results, actions, createNodeId, reporter);
142
+ const [imageNode, tableOfContents] = await (0, processor_1.processor)(pageData.results, actions, getCache, createNodeId, reporter);
147
143
  const postNode = {
148
144
  id: nodeId,
149
145
  category: parentCategoryId,
@@ -2,7 +2,6 @@
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
- // Type Guard
6
5
  function isImageBlock(block) {
7
6
  return block.type === "image" && "image" in block;
8
7
  }
@@ -0,0 +1,7 @@
1
+ import { Actions, GatsbyCache, Reporter } from "gatsby";
2
+ import { BaseContentBlock } from "notion-types";
3
+ export declare const processor: (blocks: BaseContentBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter) => Promise<(string | {
4
+ type: string;
5
+ hash: string;
6
+ title: string;
7
+ }[] | null)[]>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processor = void 0;
4
+ const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
5
+ const metadataProcessor_1 = require("./metadataProcessor");
6
+ const tableOfContent_1 = require("./tableOfContent");
7
+ const processor = async (blocks, actions, getCache, createNodeId, reporter) => {
8
+ const { thumbnail, tableOfContents } = await processBlocksForContent(blocks, actions, getCache, createNodeId, reporter);
9
+ await (0, metadataProcessor_1.processMetadata)(blocks, actions, createNodeId, reporter);
10
+ return [thumbnail, tableOfContents];
11
+ };
12
+ exports.processor = processor;
13
+ const processBlocksForContent = async (blocks, actions, getCache, createNodeId, reporter) => {
14
+ const { createNode } = actions;
15
+ const tableOfContents = [];
16
+ let thumbnail = null;
17
+ for (const block of blocks) {
18
+ await (0, tableOfContent_1.processTableOfContents)(block, tableOfContents);
19
+ if (isImageBlock(block)) {
20
+ thumbnail ||= await processImageBlock(block, actions, getCache, createNodeId, reporter);
21
+ }
22
+ }
23
+ return { thumbnail, tableOfContents };
24
+ };
25
+ const isImageBlock = (block) => {
26
+ return block.type === "image" && "image" in block;
27
+ };
28
+ const processImageBlock = async (block, actions, getCache, createNodeId, reporter) => {
29
+ const { createNode } = actions;
30
+ if (block.type === "image" && "image" in block) {
31
+ const imageSourceType = block.image.type;
32
+ const imageUrl = imageSourceType === `external`
33
+ ? block.image.external?.url
34
+ : block.image?.file?.url;
35
+ if (!imageUrl)
36
+ return null;
37
+ try {
38
+ const fileNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
39
+ url: imageUrl,
40
+ parentNodeId: block.id,
41
+ getCache,
42
+ createNode,
43
+ createNodeId,
44
+ });
45
+ if (fileNode) {
46
+ block.image = {
47
+ fileId: fileNode.id,
48
+ caption: block.image.caption,
49
+ };
50
+ reporter.info(`[SUCCESS] Image processed: ${fileNode.id}`);
51
+ return fileNode.id;
52
+ }
53
+ }
54
+ catch (error) {
55
+ reporter.warn(`[WARNING] Failed to download image: ${imageUrl}`);
56
+ }
57
+ }
58
+ return null;
59
+ };
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,7 +1,6 @@
1
- import { Actions, GatsbyCache, Reporter } from "gatsby";
2
1
  import { BaseContentBlock } from "notion-types";
3
- export declare const processTableOfContents: (blocks: BaseContentBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter) => Promise<{
2
+ export declare const processTableOfContents: (block: BaseContentBlock, tableOfContents: {
4
3
  type: string;
5
4
  hash: string;
6
5
  title: string;
7
- }[]>;
6
+ }[]) => Promise<void>;
@@ -1,30 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processTableOfContents = void 0;
4
- const isHeading = (block) => {
5
- return ["heading_1", "heading_2", "heading_3"].includes(block.type);
6
- };
7
- const processTableOfContents = async (blocks, actions, getCache, createNodeId, reporter) => {
8
- const tableOfContents = [];
9
- for (const block of blocks) {
10
- if (isHeading(block) &&
11
- (block.type === "heading_1" ||
12
- block.type === "heading_2" ||
13
- block.type === "heading_3")) {
14
- const plainText = block[block.type]?.rich_text[0]?.plain_text || "";
15
- const hash = `link-${plainText
16
- .replace(/[^a-zA-Z0-9가-힣\s-_]/g, "")
17
- .trim()
18
- .replace(/\s+/g, "-")
19
- .toLowerCase()}`;
20
- block.hash = hash;
21
- tableOfContents.push({
22
- type: block.type,
23
- hash,
24
- title: plainText,
25
- });
26
- }
4
+ const processTableOfContents = async (block, tableOfContents) => {
5
+ if (["heading_1", "heading_2", "heading_3"].includes(block.type) &&
6
+ block[block.type]?.rich_text?.length > 0) {
7
+ const plainText = block[block.type]?.rich_text?.[0]?.plain_text || "";
8
+ const hash = `link-${plainText
9
+ .replace(/[^a-zA-Z0-9가-힣\s-_]/g, "")
10
+ .trim()
11
+ .replace(/\s+/g, "-")
12
+ .toLowerCase()}`;
13
+ block.hash = hash;
14
+ tableOfContents.push({
15
+ type: block.type,
16
+ hash,
17
+ title: plainText,
18
+ });
27
19
  }
28
- return tableOfContents;
29
20
  };
30
21
  exports.processTableOfContents = processTableOfContents;
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.62",
4
+ "version": "1.0.64",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",