Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add playground #109

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ package-lock.json
# misc
demo.ts
test.md
test.json
test.json

.env
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -49,4 +50,4 @@
"markdown-table": "^2.0.0",
"node-fetch": "2"
}
}
}
2 changes: 2 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SECRET_KEY =
PAGE_ID =
20 changes: 20 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
35 changes: 35 additions & 0 deletions playground/src/index.ts
Original file line number Diff line number Diff line change
@@ -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" });
})();
24 changes: 24 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2019",
"target": "ES2020",
"lib": [
"ES2019"
"ES2020"
],
"module": "commonjs",
"resolveJsonModule": true,
Expand All @@ -26,4 +26,4 @@
"include": [
"./src/**/*.ts"
]
}
}