Til4
Automation TIL with Notion
노션 관련 npm을 적용해서 Notion 의 MD파일을 추출해 github 업로드 자동화 작업 수행 현재 demo로 테스트만 작업하였고 추후 노션 데이터베이스 접근 로직 및 방식 추가 후 적용 예정.
github workflow를 통해서 매일 11시 30분에 자동으로 Push하도록 처리하고 이를 현재 planting-grass.github.io의 워크플로우에 적합한 파일명을 강제하여 처리할 예정입니다.
const { Client } = require("@notionhq/client");
const { NotionToMarkdown } = require("notion-to-md");
const fs = require("fs");
const path = require("path");
// Load Notion Token From GitHub Secret
const NOTION_TOKEN = process.env.NOTION_TOKEN;
if (!NOTION_TOKEN) {
console.error("❌ NOTION_TOKEN is not set. Please add it to GitHub Secrets.");
process.exit(1);
}
// Initialize Client
const notion = new Client({ auth: NOTION_TOKEN });
const n2m = new NotionToMarkdown({ notionClient: notion });
// 날짜 문자열 생성 (YYYY-MM-DD)
const today = new Date().toISOString().slice(0, 10);
// export page id
// TODO : change logic
// TODO : database 지정 로직 고려해보기
// 8-4-4-4-12
const PAGE_ID = "241b48e0-c8ae-8023-b3e3-ede1805a25c3";
(async () => {
try {
const mdBlocks = await n2m.pageToMarkdown(PAGE_ID);
const mdString = n2m.toMarkdownString(mdBlocks);
const outputDir = path.resolve(__dirname, "til");
const filePath = path.join(outputDir, `${today}.md`);
fs.mkdirSync(outputDir, { recursive: true });
fs.writeFileSync(filePath, mdString.parent, "utf-8");
console.log(`✅ TIL saved to ${filePath}`);
} catch (error) {
console.error("❌ Failed to export TIL:", error.message);
process.exit(1);
}
})();
알고리즘은 언제..?