gatsby-source-notion-churnotion 1.0.59 → 1.0.60

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ const fetchData_1 = require("../util/fetchData");
10
10
  const imageProcessor_1 = require("../util/imageProcessor");
11
11
  const slugify_1 = require("../util/slugify");
12
12
  const tableOfContent_1 = require("../util/tableOfContent");
13
+ const metadataProcessor_1 = require("../util/metadataProcessor");
13
14
  const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, }) => {
14
15
  /**
15
16
  * 데이터베이스 내에 페이지들을 읽어서 재귀적으로 추가하는 서브 메서드드
@@ -142,6 +143,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
142
143
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
143
144
  const imageNode = await (0, imageProcessor_1.processBlocks)(pageData.results, actions, getCache, createNodeId, reporter);
144
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);
145
147
  const postNode = {
146
148
  id: nodeId,
147
149
  category: parentCategoryId,
@@ -6,6 +6,7 @@ export declare const NODE_TYPE: {
6
6
  Category: string;
7
7
  Tag: string;
8
8
  Book: string;
9
+ Metadata: string;
9
10
  };
10
11
  export declare const COMMON_URI = "blog";
11
12
  export declare const POST_URI = "post";
package/dist/constants.js CHANGED
@@ -10,6 +10,7 @@ exports.NODE_TYPE = {
10
10
  Category: `NCategory`,
11
11
  Tag: `NTag`,
12
12
  Book: `NBook`,
13
+ Metadata: `NMetadata`,
13
14
  };
14
15
  ///////////////url resource///////////////////////
15
16
  exports.COMMON_URI = `blog`;
@@ -53,6 +53,14 @@ const createSchemaCustomization = ({ actions }) => {
53
53
  url: String!
54
54
  book_category: ${constants_1.NODE_TYPE.Category} @link(by: "id")
55
55
  }
56
+
57
+ type ${constants_1.NODE_TYPE.Metadata} implements Node {
58
+ id: ID!,
59
+ title: String,
60
+ description: String,
61
+ image: String,
62
+ url: String,
63
+ }
56
64
  `);
57
65
  };
58
66
  exports.createSchemaCustomization = createSchemaCustomization;
@@ -0,0 +1,2 @@
1
+ import { Actions, Reporter } from "gatsby";
2
+ export declare const processMetadata: (blocks: any[], actions: Actions, createNodeId: (input: string) => string, reporter: Reporter) => Promise<any[]>;
@@ -0,0 +1,70 @@
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.processMetadata = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const metascraper_1 = __importDefault(require("metascraper"));
9
+ const metascraper_description_1 = __importDefault(require("metascraper-description"));
10
+ const metascraper_image_1 = __importDefault(require("metascraper-image"));
11
+ const metascraper_title_1 = __importDefault(require("metascraper-title"));
12
+ const metascraper_url_1 = __importDefault(require("metascraper-url"));
13
+ const constants_1 = require("../constants");
14
+ const scraper = (0, metascraper_1.default)([
15
+ (0, metascraper_url_1.default)(),
16
+ (0, metascraper_title_1.default)(),
17
+ (0, metascraper_description_1.default)(),
18
+ (0, metascraper_image_1.default)(),
19
+ ]);
20
+ const processMetadata = async (blocks, actions, createNodeId, reporter) => {
21
+ const { createNode } = actions;
22
+ for (const block of blocks) {
23
+ if (block.type === "text" || block.type === "paragraph") {
24
+ const richText = block[block.type]?.rich_text || [];
25
+ for (const text of richText) {
26
+ const href = text.href;
27
+ if (href) {
28
+ try {
29
+ reporter.info(`[INFO] Fetching metadata for URL: ${href}`);
30
+ const response = await fetch(href, {
31
+ headers: { "User-Agent": "Mozilla/5.0" },
32
+ });
33
+ const html = await response.text();
34
+ const metadata = await scraper({ html, url: href });
35
+ const nodeId = createNodeId(`${crypto_1.default.createHash("md5").update(href).digest("hex")}-metadata`);
36
+ const metadataNode = {
37
+ id: nodeId,
38
+ parent: null,
39
+ children: [],
40
+ internal: {
41
+ type: constants_1.NODE_TYPE.Metadata,
42
+ contentDigest: crypto_1.default
43
+ .createHash("md5")
44
+ .update(JSON.stringify(metadata))
45
+ .digest("hex"),
46
+ },
47
+ title: metadata.title || "",
48
+ description: metadata.description || "",
49
+ image: metadata.image || "",
50
+ url: metadata.url || href,
51
+ };
52
+ createNode(metadataNode);
53
+ reporter.info(`[SUCCESS] Created metadata node for URL: ${href}`);
54
+ text.href = nodeId;
55
+ }
56
+ catch (error) {
57
+ if (error instanceof Error) {
58
+ reporter.error(`[ERROR] Failed to fetch metadata for URL: ${href}`, error);
59
+ }
60
+ else {
61
+ console.error("Unknown error fetching metadata:", error);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return blocks;
69
+ };
70
+ exports.processMetadata = processMetadata;
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.59",
4
+ "version": "1.0.60",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",
@@ -40,6 +40,11 @@
40
40
  "gatsby-source-filesystem": "^5.14.0",
41
41
  "gatsby-transformer-json": "^5.14.0",
42
42
  "gatsby-transformer-sharp": "^5.14.0",
43
+ "metascraper": "^5.45.25",
44
+ "metascraper-description": "^5.45.25",
45
+ "metascraper-image": "^5.45.27",
46
+ "metascraper-title": "^5.45.25",
47
+ "metascraper-url": "^5.45.25",
43
48
  "node-fetch": "^3.3.2",
44
49
  "notion-to-md": "^3.1.1",
45
50
  "notion-types": "^7.1.5",