gatsby-source-notion-churnotion 1.0.63 → 1.0.64

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processor = void 0;
4
- const imageProcessor_1 = require("./imageProcessor");
5
- const tableOfContent_1 = require("./tableOfContent");
4
+ const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
6
5
  const metadataProcessor_1 = require("./metadataProcessor");
6
+ const tableOfContent_1 = require("./tableOfContent");
7
7
  const processor = async (blocks, actions, getCache, createNodeId, reporter) => {
8
- const imageNode = await (0, imageProcessor_1.processBlocks)(blocks, actions, getCache, createNodeId, reporter);
9
- const tableOfContents = await (0, tableOfContent_1.processTableOfContents)(blocks, actions, getCache, createNodeId, reporter);
8
+ const { thumbnail, tableOfContents } = await processBlocksForContent(blocks, actions, getCache, createNodeId, reporter);
10
9
  await (0, metadataProcessor_1.processMetadata)(blocks, actions, createNodeId, reporter);
11
- return [imageNode, tableOfContents];
10
+ return [thumbnail, tableOfContents];
12
11
  };
13
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
+ };
@@ -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.63",
4
+ "version": "1.0.64",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",