gatsby-source-notion-churnotion 1.0.76 → 1.0.78

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
1
  import { IGetBooksParams } from "../types";
2
- export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, cache, }: IGetBooksParams) => Promise<void>;
2
+ export declare const getBooks: ({ bookDatabaseId, reporter, getCache, createNode, createNodeId, getNode, cache, }: IGetBooksParams) => Promise<void>;
@@ -7,7 +7,8 @@ exports.getBooks = 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 getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, cache, }) => {
10
+ const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
11
+ const getBooks = async ({ bookDatabaseId, reporter, getCache, createNode, createNodeId, getNode, cache, }) => {
11
12
  const databaseUrl = `databases/${bookDatabaseId}/query`;
12
13
  const cacheKey = `booksDatabase-${bookDatabaseId}`;
13
14
  let result = await cache.get(cacheKey);
@@ -33,6 +34,14 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, ge
33
34
  if (categoryId) {
34
35
  book_category = createNodeId(`${categoryId}-category`);
35
36
  }
37
+ const bookImage = page.properties?.bookImage?.files?.[0]?.file.url;
38
+ const bookImageNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
39
+ url: bookImage,
40
+ parentNodeId: page.id,
41
+ getCache,
42
+ createNode,
43
+ createNodeId,
44
+ });
36
45
  const bookNode = {
37
46
  id: nodeId,
38
47
  book_name: page.properties?.[`이름`]?.title?.[0]?.plain_text || `Unnamed`,
@@ -50,6 +59,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, ge
50
59
  update_date: page.last_edited_time,
51
60
  url: `${constants_1.COMMON_URI}/${constants_1.BOOK_URI}/${slug}`,
52
61
  book_category: book_category,
62
+ book_image: bookImageNode,
53
63
  };
54
64
  reporter.info(`[DEBUG] Book ${bookNode.book_name} has book_category: ${bookNode.book_category}`);
55
65
  createNode(bookNode);
@@ -16,6 +16,7 @@ const sourceNodes = async (gatsbyApi, options) => {
16
16
  await (0, getBooks_1.getBooks)({
17
17
  bookDatabaseId,
18
18
  reporter,
19
+ getCache,
19
20
  createNode,
20
21
  createNodeId,
21
22
  getNode,
@@ -1,2 +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[]>;
1
+ import { Actions, GatsbyCache, Reporter } from "gatsby";
2
+ export declare const processMetadata: (blocks: any[], actions: Actions, createNodeId: (input: string) => string, reporter: Reporter, cache: GatsbyCache) => Promise<any[]>;
@@ -17,7 +17,7 @@ const scraper = (0, metascraper_1.default)([
17
17
  (0, metascraper_description_1.default)(),
18
18
  (0, metascraper_image_1.default)(),
19
19
  ]);
20
- const processMetadata = async (blocks, actions, createNodeId, reporter) => {
20
+ const processMetadata = async (blocks, actions, createNodeId, reporter, cache) => {
21
21
  const { createNode } = actions;
22
22
  for (const block of blocks) {
23
23
  if (block.type === "text" ||
@@ -31,6 +31,17 @@ const processMetadata = async (blocks, actions, createNodeId, reporter) => {
31
31
  const href = text.href;
32
32
  if (href) {
33
33
  try {
34
+ reporter.info(`[INFO] Processing metadata for URL: ${href}`);
35
+ const cacheKey = `metadata-${crypto_1.default
36
+ .createHash("md5")
37
+ .update(href)
38
+ .digest("hex")}`;
39
+ const cachedMetadata = await cache.get(cacheKey);
40
+ if (cachedMetadata) {
41
+ reporter.info(`[INFO] Using cached metadata for URL: ${href}`);
42
+ text.href = cachedMetadata.nodeId;
43
+ continue;
44
+ }
34
45
  reporter.info(`[INFO] Fetching metadata for URL: ${href}`);
35
46
  const response = await fetch(href, {
36
47
  headers: { "User-Agent": "Mozilla/5.0" },
@@ -56,6 +67,7 @@ const processMetadata = async (blocks, actions, createNodeId, reporter) => {
56
67
  };
57
68
  createNode(metadataNode);
58
69
  reporter.info(`[SUCCESS] Created metadata node for URL: ${href}`);
70
+ await cache.set(cacheKey, { ...metadata, nodeId });
59
71
  text.href = nodeId;
60
72
  }
61
73
  catch (error) {
@@ -6,7 +6,7 @@ const metadataProcessor_1 = require("./metadataProcessor");
6
6
  const tableOfContent_1 = require("./tableOfContent");
7
7
  const processor = async (blocks, actions, getCache, createNodeId, reporter, cache) => {
8
8
  const { thumbnail, tableOfContents, updatedBlocks, rawText } = await processBlocksForContent(blocks, actions, getCache, createNodeId, reporter, cache);
9
- await (0, metadataProcessor_1.processMetadata)(blocks, actions, createNodeId, reporter);
9
+ await (0, metadataProcessor_1.processMetadata)(blocks, actions, createNodeId, reporter, cache);
10
10
  return [thumbnail, tableOfContents, updatedBlocks, rawText];
11
11
  };
12
12
  exports.processor = processor;
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.76",
4
+ "version": "1.0.78",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",