From 635b1d04eae251d83eb4a9bab0151bc28c3d11df Mon Sep 17 00:00:00 2001 From: Potter <75838259@qq.com> Date: Thu, 30 May 2024 13:22:14 +0800 Subject: [PATCH 1/2] chore: update dependency --- package.json | 5 +++-- tsconfig.json | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7f68a91..aeeebde 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "prebuild": "npm run clean", "clean": "rm -rf ./build", "test": "jest", - "test:watch": "jest -w" + "test:watch": "jest -w", + "gen": "node --env-file=.env ./src/notion2md.ts" }, "keywords": [ "notion", @@ -49,4 +50,4 @@ "markdown-table": "^2.0.0", "node-fetch": "2" } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 003503b..22f84f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2019", + "target": "ES2020", "lib": [ - "ES2019" + "ES2020" ], "module": "commonjs", "resolveJsonModule": true, @@ -26,4 +26,4 @@ "include": [ "./src/**/*.ts" ] -} \ No newline at end of file +} From 5b78504b61ab7be023814d86035a08d5b0ac0094 Mon Sep 17 00:00:00 2001 From: Potter <75838259@qq.com> Date: Thu, 30 May 2024 13:22:30 +0800 Subject: [PATCH 2/2] feat: add playground --- .gitignore | 4 +++- playground/.env.example | 2 ++ playground/package.json | 20 ++++++++++++++++++++ playground/src/index.ts | 35 +++++++++++++++++++++++++++++++++++ playground/tsconfig.json | 24 ++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 playground/.env.example create mode 100644 playground/package.json create mode 100644 playground/src/index.ts create mode 100644 playground/tsconfig.json diff --git a/.gitignore b/.gitignore index 1a1009b..821d143 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,6 @@ package-lock.json # misc demo.ts test.md -test.json \ No newline at end of file +test.json + +.env diff --git a/playground/.env.example b/playground/.env.example new file mode 100644 index 0000000..f8dd6d5 --- /dev/null +++ b/playground/.env.example @@ -0,0 +1,2 @@ +SECRET_KEY = +PAGE_ID = diff --git a/playground/package.json b/playground/package.json new file mode 100644 index 0000000..1fd9ca9 --- /dev/null +++ b/playground/package.json @@ -0,0 +1,20 @@ +{ + "name": "playground", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "index.js", + "scripts": { + "gen": "tsx ./src/index.ts" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@notionhq/client": "^1.0.1", + "dotenv": "^16.4.5" + }, + "devDependencies": { + "typescript": "^5.4.5" + } +} diff --git a/playground/src/index.ts b/playground/src/index.ts new file mode 100644 index 0000000..e3f0d35 --- /dev/null +++ b/playground/src/index.ts @@ -0,0 +1,35 @@ +import fs from "fs"; +import { default as path, dirname } from "path"; +import dotenv from "dotenv"; +import { NotionToMarkdown } from "notion-to-md"; +import { Client } from "@notionhq/client"; +import { fileURLToPath } from "url" + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +dotenv.config(); + +const distPath = path.resolve(__dirname, "../dist"); + +const notion = new Client({ + auth: process.env.SECRET_KEY, +}); + +// passing notion client to the option +const n2m = new NotionToMarkdown({ notionClient: notion }); + +(async () => { + const pageDescInfos = await notion.pages.retrieve({ + auth: process.env.SECRET_KEY, page_id: process.env.PAGE_ID + }); + const mdblocks = await n2m.pageToMarkdown(process.env.PAGE_ID); + const mdString = n2m.toMarkdownString(mdblocks); + + if (!fs.existsSync("dist")) { + fs.mkdirSync("dist"); + } + + const title = (pageDescInfos as any)?.properties?.title?.title[0].plain_text; + fs.writeFileSync(path.join(distPath, `${title}.md`), mdString.parent, { encoding: "utf-8" }); +})(); diff --git a/playground/tsconfig.json b/playground/tsconfig.json new file mode 100644 index 0000000..b676444 --- /dev/null +++ b/playground/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ESNext", + "module": "ESNext", + "moduleResolution": "Node", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": false, + "skipLibCheck": true, + "noEmit": true, + "allowImportingTsExtensions": true, + "paths": { + "notion-to-md": [ + "../build" + ] + }, + "typeRoots": [ + "../build/types", + ] + }, + "include": [ + "./src/**/*.ts" + ] +}