gatsby-source-notion-churnotion 1.0.73 → 1.0.75

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.
@@ -1,2 +1,2 @@
1
1
  import { IGetBooksParams } from "../types";
2
- export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, }: IGetBooksParams) => Promise<void>;
2
+ export declare const getBooks: ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, cache, }: IGetBooksParams) => Promise<void>;
@@ -7,16 +7,26 @@ 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, }) => {
10
+ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, getNode, cache, }) => {
11
11
  const databaseUrl = `databases/${bookDatabaseId}/query`;
12
- const body = {};
13
- const result = await (0, fetchData_1.fetchPostWithRetry)(databaseUrl, body);
12
+ const cacheKey = `booksDatabase-${bookDatabaseId}`;
13
+ let result = await cache.get(cacheKey);
14
+ if (!result) {
15
+ const body = {};
16
+ result = await (0, fetchData_1.fetchPostWithRetry)(databaseUrl, body);
17
+ await cache.set(cacheKey, result);
18
+ }
14
19
  if (result?.results?.length) {
15
20
  reporter.info(`[SUCCESS] total BOOK pages > ${result.results.length}`);
16
21
  }
17
22
  for (const page of result.results) {
18
23
  reporter.info(`[CHECK] BOOK page: ${page.id}`);
19
24
  const nodeId = createNodeId(`${page.id}-book`);
25
+ const cachedNode = await cache.get(nodeId);
26
+ if (cachedNode) {
27
+ reporter.info(`[CACHE HIT] Skipping already created node: ${nodeId}`);
28
+ continue;
29
+ }
20
30
  const slug = page.properties?.slug?.rich_text?.[0]?.plain_text || `unnamed-slug`;
21
31
  const categoryId = page.properties?.category?.relation?.[0]?.id || null;
22
32
  let book_category = null;
@@ -43,6 +53,7 @@ const getBooks = async ({ bookDatabaseId, reporter, createNode, createNodeId, ge
43
53
  };
44
54
  reporter.info(`[DEBUG] Book ${bookNode.book_name} has book_category: ${bookNode.book_category}`);
45
55
  createNode(bookNode);
56
+ await cache.set(nodeId, bookNode);
46
57
  }
47
58
  };
48
59
  exports.getBooks = getBooks;
@@ -1,2 +1,2 @@
1
1
  import { IGetPagesParams } from "../types";
2
- export declare const getPages: ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, }: IGetPagesParams) => Promise<void>;
2
+ export declare const getPages: ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, cache, }: IGetPagesParams) => Promise<void>;
@@ -7,9 +7,9 @@ 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 slugify_1 = require("../util/slugify");
11
10
  const processor_1 = require("../util/processor");
12
- const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, }) => {
11
+ const slugify_1 = require("../util/slugify");
12
+ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, createNodeId, createParentChildLink, getNode, cache, }) => {
13
13
  /**
14
14
  * 데이터베이스 내에 페이지들을 읽어서 재귀적으로 추가하는 서브 메서드드
15
15
  * @param databaseId 데이터베이스 아이디
@@ -139,7 +139,7 @@ const getPages = async ({ databaseId, reporter, getCache, actions, createNode, c
139
139
  });
140
140
  }
141
141
  const bookId = page.properties?.book?.relation?.[0]?.id || null;
142
- const [imageNode, tableOfContents, updatedBlocks, rawText] = await (0, processor_1.processor)(pageData.results, actions, getCache, createNodeId, reporter);
142
+ const [imageNode, tableOfContents, updatedBlocks, rawText] = await (0, processor_1.processor)(pageData.results, actions, getCache, createNodeId, reporter, cache);
143
143
  const postNode = {
144
144
  id: nodeId,
145
145
  category: parentCategoryId,
@@ -2,4 +2,3 @@ export type { IPluginOptions } from "./types";
2
2
  export { onPluginInit } from "./onPluginInit";
3
3
  export { sourceNodes } from "./source-nodes";
4
4
  export { createSchemaCustomization } from "./createSchemaCustomization";
5
- export { onPostBootstrap } from "./onPostBootstrap";
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.onPostBootstrap = exports.createSchemaCustomization = exports.sourceNodes = exports.onPluginInit = void 0;
4
- require("@babel/register")({
5
- extensions: [".js", ".ts"],
6
- ignore: [/node_modules\/(?!kiwi-nlp)/],
7
- });
3
+ exports.createSchemaCustomization = exports.sourceNodes = exports.onPluginInit = void 0;
8
4
  var onPluginInit_1 = require("./onPluginInit");
9
5
  Object.defineProperty(exports, "onPluginInit", { enumerable: true, get: function () { return onPluginInit_1.onPluginInit; } });
10
6
  var source_nodes_1 = require("./source-nodes");
11
7
  Object.defineProperty(exports, "sourceNodes", { enumerable: true, get: function () { return source_nodes_1.sourceNodes; } });
12
8
  var createSchemaCustomization_1 = require("./createSchemaCustomization");
13
9
  Object.defineProperty(exports, "createSchemaCustomization", { enumerable: true, get: function () { return createSchemaCustomization_1.createSchemaCustomization; } });
14
- var onPostBootstrap_1 = require("./onPostBootstrap");
15
- Object.defineProperty(exports, "onPostBootstrap", { enumerable: true, get: function () { return onPostBootstrap_1.onPostBootstrap; } });
10
+ // export { onPostBootstrap } from "./onPostBootstrap";
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -88,24 +55,15 @@ const getTextFromRawText = async (doc) => {
88
55
  .replace(/http[^ ]+/g, "")
89
56
  .replace(/[\#\!\(\)\*\_\[\]\|\=\>\+\`\:\-]/g, "");
90
57
  };
91
- const getSpaceSeparatedDoc = async (doc, kiwi) => {
92
- return kiwi.tokenize(doc).map((tokenInfo) => tokenInfo.str);
58
+ const getSpaceSeparatedDoc = async (doc) => {
59
+ return "";
93
60
  };
94
- const onPostBootstrap = async ({ actions, getNode, getNodesByType, createNodeId, reporter, cache, }) => {
95
- const { KiwiBuilder } = await Promise.resolve().then(() => __importStar(require("kiwi-nlp")));
96
- const builder = await KiwiBuilder.create("/dist/kiwi-wasm.wasm");
97
- const kiwi = await builder.build({
98
- modelFiles: {
99
- "combiningRule.txt": "/dist/model/combiningRule.txt",
100
- "default.dict": "/dist/model/default.dict",
101
- "extract.mdl": "/dist/model/extract.mdl",
102
- "multi.dict": "/dist/model/multi.dict",
103
- "sj.knlm": "/dist/model/sj.knlm",
104
- "sj.morph": "/dist/model/sj.morph",
105
- "skipbigram.mdl": "/dist/model/skipbigram.mdl",
106
- "typo.dict": "/dist/model/typo.dict",
107
- },
108
- });
61
+ const onPostBootstrap = async ({ actions, getNode, getNodesByType, createNodeId, reporter, cache }, options) => {
62
+ const { etriToken } = options;
63
+ if (etriToken === "") {
64
+ reporter.info("[Related Post] Skip getting related post logic.");
65
+ return;
66
+ }
109
67
  const nodes = getNodesByType(constants_1.NODE_TYPE.Post);
110
68
  const docs = nodes.map((node) => ({
111
69
  id: node.id,
@@ -121,7 +79,7 @@ const onPostBootstrap = async ({ actions, getNode, getNodesByType, createNodeId,
121
79
  tfidf.addDocument(cached_ssd);
122
80
  }
123
81
  else {
124
- const ssd = await getSpaceSeparatedDoc(await getTextFromRawText(doc.text), kiwi);
82
+ const ssd = await getSpaceSeparatedDoc(await getTextFromRawText(doc.text));
125
83
  tfidf.addDocument(ssd);
126
84
  await cache.set(key, ssd);
127
85
  }
@@ -4,7 +4,7 @@ exports.sourceNodes = void 0;
4
4
  const getPages_1 = require("./api/getPages");
5
5
  const getBooks_1 = require("./api/getBooks");
6
6
  const sourceNodes = async (gatsbyApi, options) => {
7
- const { actions, reporter, createNodeId, getNode, getCache } = gatsbyApi;
7
+ const { actions, reporter, createNodeId, getNode, getCache, cache } = gatsbyApi;
8
8
  const { createNode, createParentChildLink } = actions;
9
9
  const { token, databaseId, bookDatabaseId } = options;
10
10
  if (!token || !databaseId) {
@@ -19,6 +19,7 @@ const sourceNodes = async (gatsbyApi, options) => {
19
19
  createNode,
20
20
  createNodeId,
21
21
  getNode,
22
+ cache,
22
23
  });
23
24
  await (0, getPages_1.getPages)({
24
25
  token,
@@ -30,6 +31,7 @@ const sourceNodes = async (gatsbyApi, options) => {
30
31
  createNodeId,
31
32
  createParentChildLink,
32
33
  getNode,
34
+ cache,
33
35
  });
34
36
  }
35
37
  catch (e) {
@@ -0,0 +1 @@
1
+ export declare const etriApi: (apiKey: string, text: string, analysisCode?: string) => Promise<any>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.etriApi = void 0;
4
+ const etriApi = async (apiKey, text, analysisCode = "morp") => {
5
+ try {
6
+ const response = await fetch("http://aiopen.etri.re.kr:8000/WiseNLU", {
7
+ method: "POST",
8
+ headers: {
9
+ Authorization: apiKey,
10
+ "Content-Type": "application/json",
11
+ },
12
+ body: JSON.stringify({
13
+ request_id: "reserved field",
14
+ argument: {
15
+ analysis_code: analysisCode,
16
+ text: text,
17
+ },
18
+ }),
19
+ });
20
+ if (!response.ok) {
21
+ throw new Error(`HTTP error! status: ${response.status}`);
22
+ }
23
+ const result = await response.json();
24
+ return result;
25
+ }
26
+ catch (error) {
27
+ console.error("Error calling ETRI API:", error);
28
+ throw error;
29
+ }
30
+ };
31
+ exports.etriApi = etriApi;
@@ -1,6 +1,6 @@
1
1
  import { Actions, GatsbyCache, Reporter } from "gatsby";
2
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 | null, {
3
+ export declare const processor: (blocks: BaseContentBlock[], actions: Actions, getCache: (this: void, id: string) => GatsbyCache, createNodeId: (this: void, input: string) => string, reporter: Reporter, cache: GatsbyCache) => Promise<[string | null, {
4
4
  type: string;
5
5
  hash: string;
6
6
  title: string;
@@ -4,13 +4,13 @@ exports.processor = void 0;
4
4
  const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
5
5
  const metadataProcessor_1 = require("./metadataProcessor");
6
6
  const tableOfContent_1 = require("./tableOfContent");
7
- const processor = async (blocks, actions, getCache, createNodeId, reporter) => {
8
- const { thumbnail, tableOfContents, updatedBlocks, rawText } = await processBlocksForContent(blocks, actions, getCache, createNodeId, reporter);
7
+ const processor = async (blocks, actions, getCache, createNodeId, reporter, cache) => {
8
+ const { thumbnail, tableOfContents, updatedBlocks, rawText } = await processBlocksForContent(blocks, actions, getCache, createNodeId, reporter, cache);
9
9
  await (0, metadataProcessor_1.processMetadata)(blocks, actions, createNodeId, reporter);
10
10
  return [thumbnail, tableOfContents, updatedBlocks, rawText];
11
11
  };
12
12
  exports.processor = processor;
13
- const processBlocksForContent = async (blocks, actions, getCache, createNodeId, reporter) => {
13
+ const processBlocksForContent = async (blocks, actions, getCache, createNodeId, reporter, cache) => {
14
14
  const tableOfContents = [];
15
15
  let thumbnail = null;
16
16
  let rawText = "";
@@ -21,7 +21,7 @@ const processBlocksForContent = async (blocks, actions, getCache, createNodeId,
21
21
  rawText += plainText + " ";
22
22
  }
23
23
  if (isImageBlock(block)) {
24
- const updatedBlock = await processImageBlock(block, actions, getCache, createNodeId, reporter);
24
+ const updatedBlock = await processImageBlock(block, actions, getCache, createNodeId, reporter, cache);
25
25
  if (!thumbnail && updatedBlock?.image?.fileId) {
26
26
  thumbnail = updatedBlock.image.fileId;
27
27
  }
@@ -58,7 +58,7 @@ const extractPlainText = (block) => {
58
58
  const isImageBlock = (block) => {
59
59
  return block.type === "image" && "image" in block;
60
60
  };
61
- const processImageBlock = async (block, actions, getCache, createNodeId, reporter) => {
61
+ const processImageBlock = async (block, actions, getCache, createNodeId, reporter, cache) => {
62
62
  const { createNode } = actions;
63
63
  if (block.type === "image" && "image" in block) {
64
64
  const imageSourceType = block.image.type;
@@ -67,6 +67,19 @@ const processImageBlock = async (block, actions, getCache, createNodeId, reporte
67
67
  : block.image?.file?.url;
68
68
  if (!imageUrl)
69
69
  return null;
70
+ const cacheKey = `${imageUrl}-post-image`;
71
+ const cachedFileNodeId = await cache.get(cacheKey);
72
+ if (cachedFileNodeId) {
73
+ reporter.info(`[CACHE HIT] Image already processed: ${imageUrl}`);
74
+ const updatedBlock = {
75
+ ...block,
76
+ image: {
77
+ fileId: cachedFileNodeId,
78
+ caption: block.image.caption,
79
+ },
80
+ };
81
+ return updatedBlock;
82
+ }
70
83
  try {
71
84
  const fileNode = await (0, gatsby_source_filesystem_1.createRemoteFileNode)({
72
85
  url: imageUrl,
@@ -84,6 +97,7 @@ const processImageBlock = async (block, actions, getCache, createNodeId, reporte
84
97
  },
85
98
  };
86
99
  reporter.info(`[SUCCESS] Image processed: ${fileNode.id}`);
100
+ await cache.set(cacheKey, fileNode.id);
87
101
  return updatedBlock;
88
102
  }
89
103
  }
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.73",
4
+ "version": "1.0.75",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",
@@ -41,7 +41,6 @@
41
41
  "gatsby-source-filesystem": "^5.14.0",
42
42
  "gatsby-transformer-json": "^5.14.0",
43
43
  "gatsby-transformer-sharp": "^5.14.0",
44
- "kiwi-nlp": "^0.20.3",
45
44
  "metascraper": "^5.45.25",
46
45
  "metascraper-description": "^5.45.25",
47
46
  "metascraper-image": "^5.45.27",
@@ -54,9 +53,6 @@
54
53
  "typescript": "^5.7.2"
55
54
  },
56
55
  "devDependencies": {
57
- "@babel/preset-env": "^7.26.0",
58
- "@babel/preset-typescript": "^7.26.0",
59
- "@babel/register": "^7.25.9",
60
56
  "gatsby": "^5.14.0"
61
57
  },
62
58
  "peerDependencies": {