From 8a400f0537a98d05bb9f3f1fc12e64346a7f250b Mon Sep 17 00:00:00 2001 From: rujuu <81368541+Rujuu-prog@users.noreply.github.com> Date: Mon, 14 Apr 2025 01:32:43 +0900 Subject: [PATCH 1/3] :zap: ignore dist folder --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ec45e2c..f96bb7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ node_modules/ yarn-error.log +dist/ + .history/ # sample/ .env From 531f897b9eb02f21406cd05768d60650c11e8346 Mon Sep 17 00:00:00 2001 From: rujuu <81368541+Rujuu-prog@users.noreply.github.com> Date: Mon, 14 Apr 2025 01:34:57 +0900 Subject: [PATCH 2/3] :coffin: remove dist for gitignore --- dist/index.d.ts | 2 - dist/index.js | 8 --- dist/index.js.map | 1 - dist/markdownToNotion.d.ts | 12 ---- dist/markdownToNotion.js | 114 ----------------------------------- dist/markdownToNotion.js.map | 1 - dist/readMD.d.ts | 17 ------ dist/readMD.js | 75 ----------------------- dist/readMD.js.map | 1 - dist/searchPage.d.ts | 18 ------ dist/searchPage.js | 50 --------------- dist/searchPage.js.map | 1 - dist/syncMd2Notion.js | 88 --------------------------- 13 files changed, 388 deletions(-) delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 dist/markdownToNotion.d.ts delete mode 100644 dist/markdownToNotion.js delete mode 100644 dist/markdownToNotion.js.map delete mode 100644 dist/readMD.d.ts delete mode 100644 dist/readMD.js delete mode 100644 dist/readMD.js.map delete mode 100644 dist/searchPage.d.ts delete mode 100644 dist/searchPage.js delete mode 100644 dist/searchPage.js.map delete mode 100644 dist/syncMd2Notion.js diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index d19662f..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { markdownToNotion } from "./markdownToNotion"; -export { searchPage } from "./searchPage"; diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 4c04f4c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.searchPage = exports.markdownToNotion = void 0; -var markdownToNotion_1 = require("./markdownToNotion"); -Object.defineProperty(exports, "markdownToNotion", { enumerable: true, get: function () { return markdownToNotion_1.markdownToNotion; } }); -var searchPage_1 = require("./searchPage"); -Object.defineProperty(exports, "searchPage", { enumerable: true, get: function () { return searchPage_1.searchPage; } }); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 1b44a86..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA"} \ No newline at end of file diff --git a/dist/markdownToNotion.d.ts b/dist/markdownToNotion.d.ts deleted file mode 100644 index 9e7a394..0000000 --- a/dist/markdownToNotion.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Import Markdown files from the specified folder to a Notion database. - * - * @param token - The Notion API token. - * @param databaseId - The ID of the Notion database to import Markdown files to. - * @param mdFolderPath - The path of the folder containing the Markdown files. - * @param fileNameColumn - The name of the column in the Notion database to use for the file name. - * @param tagsColumn - The name of the column in the Notion database to use for the tags. - * @returns Returns error if an error occurs. - * @throws error If the token or database ID is missing. - */ -export declare function markdownToNotion(token: string | undefined, databaseId: string | undefined, mdFolderPath: string, fileNameColumn?: string, tagsColumn?: string): Promise; diff --git a/dist/markdownToNotion.js b/dist/markdownToNotion.js deleted file mode 100644 index 1130b6c..0000000 --- a/dist/markdownToNotion.js +++ /dev/null @@ -1,114 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.markdownToNotion = void 0; -const client_1 = require("@notionhq/client"); -const readMD_1 = require("./readMD"); -// test用 -// import * as dotenv from 'dotenv' -// dotenv.config() -// const token = process.env.NOTION_TOKEN -// const databaseId = process.env.NOTION_DATABASE_ID -// markdownToNotion(token, databaseId, 'sample/docs', 'Title', 'Tags') -// TODO: 返り値がてきとうなので整理する -/** - * Import Markdown files from the specified folder to a Notion database. - * - * @param token - The Notion API token. - * @param databaseId - The ID of the Notion database to import Markdown files to. - * @param mdFolderPath - The path of the folder containing the Markdown files. - * @param fileNameColumn - The name of the column in the Notion database to use for the file name. - * @param tagsColumn - The name of the column in the Notion database to use for the tags. - * @returns Returns error if an error occurs. - * @throws error If the token or database ID is missing. - */ -async function markdownToNotion(token, databaseId, mdFolderPath, fileNameColumn = 'Title', tagsColumn = 'Tags') { - if (!token || !databaseId) { - throw new Error('NOTION_TOKEN or NOTION_DATABASE_ID is missing'); - } - const notion = new client_1.Client({ auth: token }); - const mds = (0, readMD_1.readMD)(mdFolderPath); - try { - const existingPages = await getExistingPages(notion, databaseId); - for (const md of mds) { - await processMarkdownFile(notion, existingPages, databaseId, md, fileNameColumn, tagsColumn); - } - } - catch (error) { - handleError(error); - } -} -exports.markdownToNotion = markdownToNotion; -function handleError(error) { - if (error instanceof Error) { - console.error('An error occurred:', error.message); - } - else { - console.error('An unknown error occurred:', error); - } -} -async function getExistingPages(notion, databaseId) { - const existingPages = await notion.databases.query({ - database_id: databaseId, - sorts: [ - { - property: 'Title', - direction: 'ascending' - } - ] - }); - // TODO: 上手く型定義できないのでanyにしている - // DB上のタイトルを取得し配列に格納 - const existingPageTitles = {}; - existingPages.results.forEach((page) => { - existingPageTitles[page.id] = page.properties.Title.title[0].text.content; - }); - return existingPageTitles; -} -async function processMarkdownFile(notion, existingPageTitles, databaseId, md, fileNameColumn = 'Title', tagsColumn = 'Tags') { - try { - // すでに存在するページの場合は削除処理(アーカイブへ) - if (Object.values(existingPageTitles).includes(md.fileName)) { - const pageId = Object.keys(existingPageTitles).find((key) => existingPageTitles[key] === md.fileName); - if (pageId) { - await archivePage(notion, pageId); - } - else { - throw new Error('page_id is not found'); - } - } - await createPage(notion, databaseId, md, fileNameColumn, tagsColumn); - } - catch (error) { - handleError(error); - } -} -async function archivePage(notion, pageId) { - const resDelete = await notion.pages.update({ - page_id: pageId, - archived: true - }); -} -async function createPage(notion, databaseId, md, fileNameColumn = 'Title', tagsColumn = 'Tags') { - const resCreate = await notion.pages.create({ - parent: { - type: 'database_id', - database_id: databaseId - }, - properties: { - [fileNameColumn]: { - title: [ - { - text: { - content: md.fileName - } - } - ] - }, - [tagsColumn]: { - multi_select: md.folderNames - } - }, - children: md.blockContent - }); -} -//# sourceMappingURL=markdownToNotion.js.map \ No newline at end of file diff --git a/dist/markdownToNotion.js.map b/dist/markdownToNotion.js.map deleted file mode 100644 index e757c69..0000000 --- a/dist/markdownToNotion.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"markdownToNotion.js","sourceRoot":"","sources":["../src/markdownToNotion.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,qCAAiC;AAIjC,QAAQ;AACR,mCAAmC;AACnC,kBAAkB;AAClB,yCAAyC;AACzC,oDAAoD;AACpD,sEAAsE;AAEtE,wBAAwB;AAExB;;;;;;;;;;GAUG;AACI,KAAK,UAAU,gBAAgB,CAAE,KAAsB,EAAE,UAA2B,EACzF,YAAmB,EACnB,iBAAyB,OAAO,EAChC,aAAqB,MAAM;IAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;KACjE;IAED,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1C,MAAM,GAAG,GAAG,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;IAEhC,IAAI;QACF,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;QAChE,KAAK,MAAM,EAAE,IAAI,G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AC,YAAY;KAC1B,CAAC,CAAA;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/readMD.d.ts b/dist/readMD.d.ts deleted file mode 100644 index baa56fc..0000000 --- a/dist/readMD.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -interface FolderName { - name: string; -} -interface MarkdownFileData { - folderNames: FolderName[]; - fileName: string; - blockContent: any; -} -/** - * Read and process Markdown files from a specified directory. - * The function reads all Markdown files in the directory and its subdirectories, extracts their content, and converts it to Notion block format. - * - * @param dirPath - The path to the directory containing the Markdown files. - * @returns An array of MarkdownFileData objects containing folder names, file names, and Notion block content. - */ -export declare function readMD(dirPath: string): MarkdownFileData[]; -export {}; diff --git a/dist/readMD.js b/dist/readMD.js deleted file mode 100644 index 4215440..0000000 --- a/dist/readMD.js +++ /dev/null @@ -1,75 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.readMD = void 0; -const fs = __importStar(require("fs")); -const path = __importStar(require("path")); -const gray_matter_1 = __importDefault(require("gray-matter")); -const martian_1 = require("@tryfabric/martian"); -function removeMarkdownLinks(content) { - // ページ内リンクの正規表現 - const linkPattern = /\[([^\]]+)]\(#([^\)]+)\)/g; - return content.replace(linkPattern, '$1'); -} -/** - * Read and process Markdown files from a specified directory. - * The function reads all Markdown files in the directory and its subdirectories, extracts their content, and converts it to Notion block format. - * - * @param dirPath - The path to the directory containing the Markdown files. - * @returns An array of MarkdownFileData objects containing folder names, file names, and Notion block content. - */ -function readMD(dirPath) { - const result = []; - function walk(currentPath) { - const entries = fs.readdirSync(currentPath, { withFileTypes: true }); - for (const entry of entries) { - const entryPath = path.join(currentPath, entry.name); - if (entry.isDirectory()) { - walk(entryPath); - } - else if (entry.isFile() && entry.name.endsWith('.md')) { - const content = (0, gray_matter_1.default)(fs.readFileSync(entryPath, 'utf-8')).content; - const noLinkContent = removeMarkdownLinks(content); - const blockContent = (0, martian_1.markdownToBlocks)(noLinkContent); - const relativePath = path.relative(dirPath, entryPath); - const pathParts = relativePath.split(path.sep); - const fileNameWithExtension = pathParts.pop(); - const fileNameWithoutExtension = path.basename(fileNameWithExtension, '.md'); - const folderNames = pathParts.map(folderName => ({ name: folderName })); - result.push({ folderNames, fileName: fileNameWithoutExtension, blockContent }); - } - } - } - walk(dirPath); - return result; -} -exports.readMD = readMD; -// const markdownFiles = readMD('sample'); -// console.dir(markdownFiles); -// console.log('%o', markdownFiles); -//# sourceMappingURL=readMD.js.map \ No newline at end of file diff --git a/dist/readMD.js.map b/dist/readMD.js.map deleted file mode 100644 index 1c86ecd..0000000 --- a/dist/readMD.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"readMD.js","sourceRoot":"","sources":["../src/readMD.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,2CAA4B;AAC5B,8DAAgC;AAChC,gDAAqD;AAYrD,SAAS,mBAAmB,CAAC,OAAe;IACxC,eAAe;IACf,MAAM,WAAW,GAAG,2BAA2B,CAAA;I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AC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;gBAEvE,MAAM,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB,EAAE,YAAY,EAAE,CAAC,CAAA;aAC/E;SACF;IACH,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,CAAA;IACb,OAAO,MAAM,CAAA;AACf,CAAC;AA7BD,wBA6BC;AAED,0CAA0C;AAC1C,8BAA8B;AAC9B,oCAAoC"} \ No newline at end of file diff --git a/dist/searchPage.d.ts b/dist/searchPage.d.ts deleted file mode 100644 index 2476e87..0000000 --- a/dist/searchPage.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -interface QueryResult { - results: any[]; - next_cursor: string | null; - has_more: boolean; -} -/** - * Search a Notion database for a page with a specific title and tags. - * - * @param token - Notion API token. - * @param databaseId - The ID of the database to search. - * @param fileNameColumn - The column name for the file title (default: 'Title'). - * @param tagsColumn - The column name for the tags (default: 'Tags'). - * @param title - The title of the page to search for. - * @param tags - An array of tags to filter the search results. - * @returns A Promise resolving to the database query result. - */ -export declare function searchPage(token: string, databaseId: string, fileNameColumn: string | undefined, tagsColumn: string | undefined, title: string, tags: Array): Promise; -export {}; diff --git a/dist/searchPage.js b/dist/searchPage.js deleted file mode 100644 index 3ac92b7..0000000 --- a/dist/searchPage.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.searchPage = void 0; -const client_1 = require("@notionhq/client"); -/** - * Search a Notion database for a page with a specific title and tags. - * - * @param token - Notion API token. - * @param databaseId - The ID of the database to search. - * @param fileNameColumn - The column name for the file title (default: 'Title'). - * @param tagsColumn - The column name for the tags (default: 'Tags'). - * @param title - The title of the page to search for. - * @param tags - An array of tags to filter the search results. - * @returns A Promise resolving to the database query result. - */ -async function searchPage(token, databaseId, fileNameColumn = 'Title', tagsColumn = 'Tags', title, tags) { - const notion = new client_1.Client({ auth: token }); - // Create the tag filters from the input tags array - const tagFilters = tags.map(tag => ({ - property: tagsColumn, - multi_select: { - contains: tag, - }, - })); - // Perform the database query with the specified filters - try { - const response = await notion.databases.query({ - database_id: databaseId, - filter: { - and: [ - { - property: fileNameColumn, - rich_text: { - equals: title, - }, - }, - ...tagFilters, - ], - }, - }); - return response; - } - catch (error) { - // Handle any errors that occur during the API call - console.error('Error querying the Notion database:', error); - throw error; - } -} -exports.searchPage = searchPage; -//# sourceMappingURL=searchPage.js.map \ No newline at end of file diff --git a/dist/searchPage.js.map b/dist/searchPage.js.map deleted file mode 100644 index cfb1497..0000000 --- a/dist/searchPage.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"searchPage.js","sourceRoot":"","sources":["../src/searchPage.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAS1C;;;;;;;;;;GAUG;AACI,KAAK,UAAU,UAAU,CAC9B,KAAa,EACb,UAAkB,EAClB,iBAAyB,OAAO,EAChC,aAAqB,MAAM,EAC3B,KAAa,EACb,IAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAE3C,mDAAmD;IACnD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClC,QAAQ,EAAE,UAAU;QACpB,YAAY,EAAE;YACZ,QAAQ,EAAE,GAAG;SACd;KACF,CAAC,CAAC,CAAC;IAEJ,wDAAwD;IACxD,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAC5C,WAAW,EAAE,UAAU;YACvB,MAAM,EAAE;gBACN,GAAG,EAAE;oBACH;wBACE,QAAQ,EAAE,cAAc;wBACxB,SAAS,EAAE;4BACT,MAAM,EAAE,KAAK;yBACd;qBACF;oBACD,GAAG,UAAU;iBACd;aACF;SACF,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;KACjB;IAAC,OAAO,KAAK,EAAE;QACd,mDAAmD;QACnD,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC5D,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAzCD,gCAyCC"} \ No newline at end of file diff --git a/dist/syncMd2Notion.js b/dist/syncMd2Notion.js deleted file mode 100644 index 652b790..0000000 --- a/dist/syncMd2Notion.js +++ /dev/null @@ -1,88 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const client_1 = require("@notionhq/client"); -const readMD_1 = require("./readMD"); -const dotenv = __importStar(require("dotenv")); -dotenv.config(); -const token = process.env.NOTION_TOKEN; -const databaseId = process.env.NOTION_DATABASE_ID; -async function main() { - const notion = new client_1.Client({ auth: token }); - const mds = (0, readMD_1.readMD)('sample'); - if (databaseId) { - const existingPages = await notion.databases.query({ - database_id: databaseId, - sorts: [ - { - property: 'Title', - direction: 'ascending', - }, - ], - }); - // TODO: 上手く型定義できないのでanyにしている - // DB上のタイトルを取得し配列に格納 - var existingPageTitles = {}; - existingPages.results.forEach((page) => { - existingPageTitles[page.id] = page.properties.Title.title[0].text.content; - }); - for (const md of mds) { - // すでに存在するページの場合は削除処理(アーカイブへ) - if (Object.values(existingPageTitles).includes(md.fileName)) { - const pageId = Object.keys(existingPageTitles).find(key => existingPageTitles[key] === md.fileName); - if (pageId) { - const resDelete = await notion.pages.update({ - "page_id": pageId, - "archived": true, - }); - } - else { - throw new Error('page_id is not found'); - } - } - const resCreate = await notion.pages.create({ - "parent": { - "type": "database_id", "database_id": databaseId - }, - "properties": { - "Title": { - "title": [ - { - "text": { - "content": md.fileName - } - } - ] - }, - "Tags": { - "multi_select": md.folderNames - }, - }, - "children": md.blockContent, - }); - } - } -} -main(); From 7c17b6b07b6768470931c210baa08f829ef1a385 Mon Sep 17 00:00:00 2001 From: rujuu <81368541+Rujuu-prog@users.noreply.github.com> Date: Mon, 14 Apr 2025 01:37:35 +0900 Subject: [PATCH 3/3] :zap: update to 1.2.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 54114e6..91cd323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown2notion", - "version": "1.2.5", + "version": "1.2.6", "description": "Convert markdown files to notion database. The folder structure is also fully represented as tags in notion.", "author": "Rujuu", "license": "MIT",