๋๋ ์ฃผ๋ก ๋ญ๊ฐ๋ฅผ ์ ๋ฆฌํ ๋๋ ๋
ธ์
์ ์ด์ฉํ๋ค. ๊ทธ๋ฐ๋ฐ ์ด๊ฑธ ๋งค๋ฒ ์ผ์ผํ ๋งํฌ๋ค์ด์ผ๋ก ๋ค์ด๋ฐ์์ Github์ ์ฌ๋ฆฌ๋ ๊ฒ์ ๋งค์ฐ ๋ฒ๊ฑฐ๋กญ๋ค. ๊ฒ๋ค๊ฐ ๋ค์ด๋ฐ์ ๋ ํ์ผ๋ช
์ด ๊นจ์ ธ์ ๋ฐ์์ง๋ค. ๊ทธ๋ฌ๋ฉด ๊ทธ๊ฑธ ๋ ์ผ์ผํ ๋ฐ๊ฟ์ผ ํ๋๋ฐ..
๋๋ ์๋นํ ๋นํจ์จ์ ์ธ ๊ฒ์ ์ซ์ดํ๊ธฐ ๋๋ฌธ์ ๋ฐฉ๋ฒ์ ์ฐพ์๋ณด์๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์ค๋์ Github Acitons๋ฅผ ์ด์ฉํด์ Github์ ์ฌ๋ฆฌ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ค๋ช
ํ๊ฒ ๋ค.
1. Notion API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ Integration ์์ฑ.
https://developers.notion.com/
Notion API
developers.notion.com
๋จผ์ , Notion API ํ์ด์ง์์ ์ Integration์ ์์ฑํ๋ค. ๋๋ ํ๋ผ์ด๋น์ผ๋ก ์ค์ ํ์๋ค. ์ ์ฅํ๋ฉด ํ ํฐ์ด ์๊ธธ ๊ฒ์ด๋ค. ํด๋น ํ ํฐ์ ์ถํ์ ์ฌ์ฉํด์ผ ํ๋ ๋ฏธ๋ฆฌ ๋ณต์ฌํด๋๋ค.
2. ๊ณต์ ํ๊ณ ์ ํ๋ ํ์ด์ง์ Integration ์ถ๊ฐ
์ ๋ฐ์ด ์ธ๊ฐ๋ฅผ ๋๋ฅด๋ฉด ์ฐ๊ฒฐ์ด๋ผ๊ณ ์๋ค. ์ฌ๊ธฐ์ ์์์ ๋ง๋ Notion API๋ฅผ ์ฐ๊ฒฐํ๋ฉด ๋๋ค.
3. ์คํฌ๋ฆฝํธ ์์ฑ
Notion ๋ฐ์ดํฐ๋ฅผ Markdown์ผ๋ก ๋ณํ์ํค๋ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํด์ผ ํ๋ค. ๋๋ Notion-to-md๋ผ๋ ํจํค์ง๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด JavaScript๋ก ์์ฑํ์๋ค.
https://www.npmjs.com/package/notion-to-md/v/1.0.1
notion-to-md
convert notion pages, block and list of blocks to markdown (supports nesting). Latest version: 3.1.5, last published: 4 days ago. Start using notion-to-md in your project by running `npm i notion-to-md`. There are 67 other projects in the npm registry usin
www.npmjs.com
import { Client } from '@notionhq/client';
import { NotionToMarkdown } from 'notion-to-md';
import { existsSync } from 'node:fs';
import { mkdirSync } from 'node:fs';
import { writeFileSync } from 'node:fs';
import dotenv from 'dotenv';
dotenv.config();
const notion = new Client({auth : process.env.NOTION_API_KEY});
const n2m = new NotionToMarkdown({
notionClient: notion,
config: {
seperateChildPage: true,
}
});
const databaseId = process.env.DATABASE_ID;
(async () => {
try {
const response = await notion.databases.query({
database_id: databaseId,
sorts: [
{
property: 'Name',
direction: 'ascending',
},
],
});
const saveDirectory = './summary';
if (!existsSync(saveDirectory)){
mkdirSync(saveDirectory);
}
const pages = response.results.map(page => {
const pageId = page.id;
const name = page.properties?.Name?.title?.[0]?.text?.content;
return {
pageId: pageId,
name: name
};
});
for (let page of pages){
const mdblocks = await n2m.pageToMarkdown(page.pageId);
const mdString = n2m.toMarkdownString(mdblocks);
const name = page.name;
let parts = name.split(":");
const filePath = `${saveDirectory}/${parts[0]}-${parts[1]}.md`;
const mdHead = `# ${page.name}\n`
const mdContent = mdHead+ mdString.parent;
writeFileSync(filePath, mdContent, "utf8");
}
} catch (error){
console.error("๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ ๋ฐ์:", error);
}
})();
n2m.toMarkdownString(mdblocks)๋ก ํ์ด์ง์ ๋ด์ฉ์ ๊ฐ์ ธ์จ๋ค. ์ด๋, ๋๋ ํ ๋ฆฌ ๊ฐ์ฒด์ด๋ฏ๋ก mdString.parent๋ก ๊ฐ์ ธ์์ผํ๋ค.
custom์์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ์ ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํด์ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ฉด ๋๋ค.
4. package.json ์์ฑํ๊ธฐ
ํ์ํ ํจํค์ง๋ค์ ์ ์ํ๊ธฐ ์ํด package.json์ ์์ฑํด์ผ ํ๋ค. ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ๋ฉด ๋๋ค.
{
"name": "ํจํค์ง๋ช
",
"version": "1.0.0",
"description": "ํจํค์ง ์ค๋ช
",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@notionhq/client": "^2.2.15",
"dotenv": "^16.4.7",
"notion-to-md": "^3.1.5"
},
"type": "module"
}
5. Github Action yaml ํ์ผ ์์ฑํ๊ธฐ
name: Convert Notion to Markdown
on:
push:
branches:
- main
schedule:
- cron: "0 */4 * * *" # 4์๊ฐ๋ง๋ค ์คํ.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 22
- name: Install dependencies
run: |
npm ci
npm install notion-to-md
- name: Convert Notion page to Markdown
env:
DATABASE_ID: ${{ secrets.DATABASE_ID }}
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
NOTION_PAGE_ID: ${{ secrets.NOTION_PAGE_ID }}
run: |
node convert.js
- name: Check if there are any changes
id: verify_diff
run: |
git diff --quiet . || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push the markdown file
if: steps.verify_diff.outputs.changed =='true'
run: |
git config --global user.name '5a6io'
git config --global user.email '${{ secrets.EMAIL }}'
git add .
git commit -m "Update Notion page to markdown"
git push origin main
npm init -y๋ package.json์ ์ ์ํ๋ค. ๊ทธ๋ฆฌ๊ณ notion-to-md๋ฅผ ํ์๋ก ์ค์นํ๋ค. ๋ ํ๊ฒฝ๋ณ์๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ dotenv๋ ์ค์นํ๋ค.
๊ทธ๋ฆฌ๊ณ verify_diff์์ changed๊ฐ true๋ผ๋ฉด ๋ด์ฉ์ด ๋ณํ ๊ฒ์ด ์์ ๋๋ง commit ๋ฐ push๊ฐ ๋ฐ์ํ๋ค. ๋ค๋ง ์ฒ์์ ํธ์๋ฅผ ํ๋ฉด ๋น๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค.
ํด๋น ๋ ํ์งํ ๋ฆฌ Settings โก๏ธ Actions โก๏ธ General ํ๋จ์ ๋ณด๋ฉด ์์ ๊ฐ์ด ๋ณด์ด๋ ๊ณณ์ด ์์ ๊ฒ์ด๋ค. ์ฒ์์๋ Read repository contents adn packages permissions๋ก ๋์ด์๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์ฐ๋ฆฌ๋ ์ฐ๊ธฐ๋ ๊ฐ๋ฅํ๊ฒ Read and write permissions๋ก ๋ฐ๊ฟ์ค์ผ ํ๋ค.
6. ๊ฒฐ๊ณผ
๊ทธ๋ฌ๋ฉด ์์ ๊ฐ์ด ๋ณํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ์ฝ๋ ๋ถ๋ถ์ indent์์ ์ ๋ ๊ฒ ๋ถ์ ๊ฒ ์๊ธฐ๊ธด ํ์ง๋ง ๊ทธ๋๋ ๋๋ฆ ๋ง์กฑํ๋ค.
GitHub - 5a6io/CKA: CKA ์ํ ๋๋น ๋ด์ฉ ์ ๋ฆฌ
CKA ์ํ ๋๋น ๋ด์ฉ ์ ๋ฆฌ. Contribute to 5a6io/CKA development by creating an account on GitHub.
github.com
ํด๋น repository๋ ์ ๋ฐฉ๋ฒ์ ์ด์ฉํด์ ๋
ธ์
์ ๊นํ๋ธ์ ์ฌ๋ ธ๋ค. ๋๋ ์ ํจํค์ง๋ฅผ ํ์ฉํด README.md๋ Github Actions๋ฅผ ์ด์ฉํด์ ์ ์ ์ ์๋๋ก ํ์๋ค.
๊ทธ๋ฐ๋ฐ ์ฌ์ค ์กฐ๊ธ ๋ถ์์ ํ๋ค. README.md๊ฐ ๋ณ๊ฒฝ์ด ๋์ด์ผ์ง verify_diff ๋ถ๋ถ์์ diff๋ฅผ ์ธ์ํด์ ๋ฐ๋๋ค. ์๋๋ฉด ์กฐ๊ฑด์ ๋นผ์ผ ํ๋๋ฐ ๊ทธ๋ฌ๋ฉด ์๋ก ๋ฐ๋ ๊ฒ ์์ ๋๋ ๋น๋ ์ค๋ฅ๊ฐ 4์๊ฐ ๋ง๋ค ์ผ์ด๋ ๊ฒ์ด๋ค. ์ด์ฐจํผ ๊ฐ์๋ฅผ ๋ค ๋ฃ๊ณ ๊ธฐ๋กํ ์๊ฐ์ด๊ธฐ ๋๋ฌธ์ ๋๋ ํฌ๊ฒ ์๊ด์ด ์์ง๋ง ์ด ๋ถ๋ถ์ ๋์ค์ ํด๊ฒฐํด๋ณด๊ฒ ๋ค.
25.02.16 ์ ๋ฐ์ดํธ
๋ถ๊ฒ ๋๋ ๊ฒ์ ๋ ธ์ ์์ ํญํค๋ฅผ ์ด์ฉํ์ฌ ๊ฐ๊ฒฉ์ ๋์ด ๊ฒ์ด ์์ธ์ด์๋ค.
'ETC' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ํ] ๊ธฐ์ด๋ถํฐ ๋ฐฐ์ฐ๋ ์ต์ ์คํ ๋ฆฌ์ง ์ ๋ฌธ (1) | 2024.12.12 |
---|---|
JLPT N1 ํฉ๊ฒฉ ํ๊ธฐ (1) | 2024.10.15 |
AWS SAA-C03 ์๊ฒฉ์ฆ ํฉ๊ฒฉ ํ๊ธฐ (1) | 2024.09.28 |