diff --git a/.github/workflows/notion2github.yml b/.github/workflows/notion2github.yml index c97fbf8..409c2b9 100644 --- a/.github/workflows/notion2github.yml +++ b/.github/workflows/notion2github.yml @@ -11,7 +11,7 @@ jobs: uses: actions/checkout@v2 - name: Notion2Github - uses: younho9/notion2github@v1.0.0-beta + uses: younho9/notion2github@main with: database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad' docs-directory: docs/test diff --git a/README.md b/README.md index 14d5152..5ca90b7 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,11 @@ [![GitHub Action: View on Marketplace](https://img.shields.io/badge/GitHub%20Action-View_on_Marketplace-blue?style=flat-square&logo=github)](https://github.com/marketplace/actions/notion2github) [![Demo: available](https://img.shields.io/badge/Demo-available-orange?style=flat-square)](.github/workflows/notion2github.yml) -[![Version: v1.0.0-beta](https://img.shields.io/badge/Version-v1.0.0--beta-brightgreen?style=flat-square)](https://github.com/younho9/narkdown/releases/tag/v1.0.0-beta) +[![Version: v1.0.1](https://img.shields.io/badge/Version-v1.0.1-brightgreen?style=flat-square)](https://github.com/younho9/notion2github/releases/tag/v1.0.1) [![license: MIT](https://img.shields.io/badge/license-MIT-yellow.svg?style=flat-square)](./LICENSE) +| [English](/README.md) | [ํ•œ๊ตญ์–ด](/docs/README.ko.md) | + **Automatic syncronization from Notion to Github** --- @@ -18,37 +20,24 @@ ## Usage -### Using encrypted token_v2 in a workflow +### Quick Start -
- notion2github-image-0 -
+1. Go to `github.com/{your_id}/{your_repo}/settings/secrets/actions` -The `token_v2` is required to get contents from Notion. The `token_v2` of notion is a variable that should not be shared. So you can use encrypted secrets in your repository. +2. Set `token_v2` of Notion to your repository secret. -For more information, See ["Using encrypted secrets in a workflow"](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow) - -### Parameters + ![notion2github-image-0](docs/images/readme-image-0.png) -| Name | Description | Required | Default | -| ---------------- | -------------------------------------------------------------- | ---------- | -------- | -| `database-url` | URL of the Notion database to extract. | `required` | | -| `docs-directory` | Directory in which the Notion pages to extract will be stored. | | `"docs"` | -| `filter-prop` | Property of the filter to apply to the notion database. | | `""` | -| `filter-value` | Value of the filter to apply to the notion database. | | `""` | + [How To Find Your Notion v2 Token - Red Gregory](https://www.redgregory.com/notion/2020/6/15/9zuzav95gwzwewdu1dspweqbv481s5) -### Database template page for test + [Encrypted secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow) -Here is an [database template page](/acc3dfd0339e4cacb5baae8673fddfad?v=be43c1c8dd644cfb9df9efd97d8af60a) for importing pages from the database. Move to that page, duplicate it, and test it. +3. Create a workflow in `.github/workflows/**.yml` of your repository -
- notion2github-image-1 -
+Here are examples. ### Example Workflow -Create workflow in `.github/workflows/**.yml` - #### Example 1 (run on push & pull request in main) ```yaml @@ -66,12 +55,10 @@ jobs: uses: actions/checkout@v2 - name: Notion2Github - uses: younho9/notion2github@v1.0.0-beta + uses: younho9/notion2github@v1.1.0 with: database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad' - docs-directory: docs/test - filter-prop: Category - filter-value: Test + docs-directory: docs env: NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} @@ -99,12 +86,10 @@ jobs: uses: actions/checkout@v2 - name: Notion2Github - uses: younho9/notion2github@v1.0.0-beta + uses: younho9/notion2github@v1.1.0 with: database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad' - docs-directory: docs/test - filter-prop: Category - filter-value: Test + docs-directory: docs env: NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} @@ -125,7 +110,26 @@ jobs: - [younho9/TIL](https://github.com/younho9/til/blob/main/.github/workflows/notion2github.yml) -## Configuring Narkdown +## Database template page for test + +Here is an [database template page](https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad?v=be43c1c8dd644cfb9df9efd97d8af60a) for importing pages from the database. Move to that page, duplicate it, and test it. + +
+ notion2github-image-1 +
+ +## Configuration + +### Parameters + +| Name | Description | Required | Default | +| ---------------- | -------------------------------------------------------------- | ---------- | -------- | +| `database-url` | URL of the Notion database to extract. | `required` | | +| `docs-directory` | Directory in which the Notion pages to extract will be stored. | | `"docs"` | +| `filter-prop` | Property of the filter to apply to the notion database. | | `""` | +| `filter-value` | Value of the filter to apply to the notion database. | | `""` | + +### Configuring Narkdown Narkdown provides some configuration for how to extract documents. You can configure Narkdown via `narkdown.config.json` . @@ -139,15 +143,12 @@ For more information on configure your environment, [see the document in Nakdown "exportConfig": { "recursiveExport": true, "createPageDirectory": true, - "addMetadata": false, - "lowerPathname": false, - "lowerFilename": false, - "lineBreak": false + "addMetadata": true, + "appendCreatedTime": true, + "generateSlug": true }, "databaseConfig": { "categoryColumnName": "Category", - "tagsColumnName": "Tags", - "createdTimeColumnName": "Created Time", "statusColumnName": "Status", "currentStatus": "โœ… Completed", "nextStatus": "๐Ÿ–จ Published" @@ -155,6 +156,16 @@ For more information on configure your environment, [see the document in Nakdown } ``` +### Used in combination with other actions + +Notion2Github is a step in the workflow, just import the contents of notion to a running virtual machine in github action. + +There are great actions to commit the imported content to your repository. + +- [Git Auto Commit - GitHub Marketplace](https://github.com/marketplace/actions/git-auto-commit) + +- [Prettier Action - GitHub Marketplace](https://github.com/marketplace/actions/prettier-action) + ### License MIT ยฉ [younho9](https://github.com/younho9) diff --git a/docs/README.ko.md b/docs/README.ko.md new file mode 100644 index 0000000..5183be0 --- /dev/null +++ b/docs/README.ko.md @@ -0,0 +1,170 @@ +Notion2Github + +# Notion2Github + +[![GitHub Action: View on Marketplace](https://img.shields.io/badge/GitHub%20Action-View_on_Marketplace-blue?style=flat-square&logo=github)](https://github.com/marketplace/actions/notion2github) +[![Demo: available](https://img.shields.io/badge/Demo-available-orange?style=flat-square)](.github/workflows/notion2github.yml) +[![Version: v1.0.1](https://img.shields.io/badge/Version-v1.0.1-brightgreen?style=flat-square)](https://github.com/younho9/notion2github/releases/tag/v1.0.1) +[![license: MIT](https://img.shields.io/badge/license-MIT-yellow.svg?style=flat-square)](./LICENSE) + +| [English](/README.md) | [ํ•œ๊ตญ์–ด](/docs/README.ko.md) | + +**๋…ธ์…˜์—์„œ ๊นƒํ—™์œผ๋กœ์˜ ์ž๋™ ๋™๊ธฐํ™”** + +--- + +> โš ๏ธ **์œ ์˜์‚ฌํ•ญ:** Notion2Github์€ [Jamie Alexandre](https://github.com/jamalex)์ด ๋งŒ๋“  **_๋น„๊ณต์‹_** ๋…ธ์…˜ API์ธ [notion-py](https://github.com/jamalex/notion-py) ํ”„๋กœ์ ํŠธ์— ์˜์กดํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ณต์‹ API๊ฐ€ ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์•ˆ์ •์ ์ด์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๋•์…˜ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด, ๋…ธ์…˜ ๊ณต์‹ API ์ถœ์‹œ๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. + +--- + +## ์‚ฌ์šฉ๋ฒ• + +### ๋ฐ”๋กœ ์‹œ์ž‘ํ•˜๊ธฐ + +1. `github.com/{your_id}/{your_repo}/settings/secrets/actions` ์œผ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค. + +1. ๋…ธ์…˜์˜ `token_v2` ๋ฅผ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ Secrets์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. + + ![notion2github-image-0](images/readme-image-0.png) + + [How To Find Your Notion v2 Token - Red Gregory](https://www.redgregory.com/notion/2020/6/15/9zuzav95gwzwewdu1dspweqbv481s5) + + [Encrypted secrets](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets#using-encrypted-secrets-in-a-workflow) + +1. ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ `.github/workflows/**.yml` ํŒŒ์ผ์— ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. + +๋ช‡ ๊ฐ€์ง€ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. + +### ์›Œํฌํ”Œ๋กœ์šฐ ์˜ˆ์ œ + +#### ์˜ˆ์ œ 1 (main ๋ธŒ๋žœ์น˜์— push & pull request ์‹œ์— ์‹คํ–‰) + +```yaml +name: Notion2Github +on: + pull_request: + push: + branches: + - main +jobs: + auto-sync-from-notion-to-github: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Notion2Github + uses: younho9/notion2github@v1.1.0 + with: + database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad' + docs-directory: docs + env: + NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} + + - name: Format documents + uses: creyD/prettier_action@v3.1 + with: + prettier_options: --write ./docs/**/*.md + commit_message: 'docs: Update docs (auto)' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +#### ์˜ˆ์ œ 2 (์ •ํ•ด์ง„ ์‹œ๊ฐ„์— ์‹คํ–‰) + +```yaml +name: Notion2Github +on: + schedule: + - cron: '0 14 * * *' +jobs: + auto-sync-from-notion-to-github: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Notion2Github + uses: younho9/notion2github@v1.1.0 + with: + database-url: 'https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad' + docs-directory: docs + env: + NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }} + + - name: Format documents + uses: creyD/prettier_action@v3.1 + with: + prettier_options: --write ./docs/**/*.md + commit_message: 'docs: Update docs (auto)' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +> [ํฌ๋ก ํƒญ ์„ค์ •์— ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ](https://crontab.guru/) + +### ์‹ค์‚ฌ์šฉ ์˜ˆ์ œ + +- [younho9/narkdown](https://github.com/younho9/narkdown/blob/main/.github/workflows/notion2github.yml) + +- [younho9/TIL](https://github.com/younho9/til/blob/main/.github/workflows/notion2github.yml) + +## ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…œํ”Œ๋ฆฟ ํŽ˜์ด์ง€ + +๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ๋ถ€ํ„ฐ ํŽ˜์ด์ง€๋“ค์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” [๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ…œํ”Œ๋ฆฟ ํŽ˜์ด์ง€](https://www.notion.so/acc3dfd0339e4cacb5baae8673fddfad?v=be43c1c8dd644cfb9df9efd97d8af60a)๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. + +ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•ด์„œ ๋ณต์ œํ•˜๊ณ  ํ…Œ์ŠคํŠธํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +
+ notion2github-image-1 +
+ +## ํ™˜๊ฒฝ์„ค์ • + +| Name | Description | Required | Default | +| ---------------- | ------------------------------------------- | ---------- | -------- | +| `database-url` | ์ถ”์ถœํ•  ๋…ธ์…˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ URL | `required` | | +| `docs-directory` | ์ถ”์ถœ๋œ ๋…ธ์…˜ ํŽ˜์ด์ง€๋“ค์ด ์ €์žฅ๋  ๋””๋ ‰ํ† ๋ฆฌ | | `"docs"` | +| `filter-prop` | ๋…ธ์…˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ์šฉํ•  ํ•„ํ„ฐ์˜ ์†์„ฑ ์ด๋ฆ„ | | `""` | +| `filter-value` | ๋…ธ์…˜ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ์šฉํ•  ํ•„ํ„ฐ์˜ ๊ฐ’ ์ด๋ฆ„ | | `""` | + +### Narkdown ํ™˜๊ฒฝ์„ค์ • + +Narkdown์€ ๋ฌธ์„œ๋“ค์„ ์–ด๋–ป๊ฒŒ ์ถ”์ถœํ•  ๊ฒƒ์ธ์ง€์— ๋Œ€ํ•ด ๋ช‡๊ฐ€์ง€ ํ™˜๊ฒฝ์„ค์ •์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. `narkdown.config.json` ํŒŒ์ผ์„ ํ†ตํ•ด์„œ Narkdown์„ ํ™˜๊ฒฝ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. + +๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ root์— `narkdown.config.json` ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์„ธ์š”. + +ํ™˜๊ฒฝ์— ๋”ฐ๋ผ ํ™˜๊ฒฝ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ๋ณด๋ ค๋ฉด [Narkdown์˜ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•˜์„ธ์š”](https://github.com/younho9/narkdown#configuring-narkdown). + +```json +// narkdown.config.json +{ + "exportConfig": { + "recursiveExport": true, + "createPageDirectory": true, + "addMetadata": true, + "appendCreatedTime": true, + "generateSlug": true + }, + "databaseConfig": { + "categoryColumnName": "Category", + "statusColumnName": "Status", + "currentStatus": "โœ… Completed", + "nextStatus": "๐Ÿ–จ Published" + } +} +``` + +### ๋‹ค๋ฅธ ์•ก์…˜๊ณผ ์กฐํ•ฉํ•˜์—ฌ ์‚ฌ์šฉ + +Notion2Github์€ ์›Œํฌํ”Œ๋กœ์šฐ์˜ ํ•œ step์œผ๋กœ ๋‹จ์ง€ github action์œผ๋กœ ์‹คํ–‰๋˜๋Š” ๊ฐ€์ƒ ๋จธ์‹ ์œผ๋กœ ๋…ธ์…˜์˜ ์ฝ˜ํ…์ธ ๋“ค์„ ๊ฐ€์ ธ์˜ฌ ๋ฟ์ž…๋‹ˆ๋‹ค. + +๋…ธ์…˜์˜ ์ฝ˜ํ…์ธ ๋“ค์„ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ ์ปค๋ฐ‹ํ•  ์ˆ˜ ์žˆ๋Š” ํ›Œ๋ฅญํ•œ action๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. + +- [Git Auto Commit - GitHub Marketplace](https://github.com/marketplace/actions/git-auto-commit) + +- [Prettier Action - GitHub Marketplace](https://github.com/marketplace/actions/prettier-action) + +### License + +MIT ยฉ [younho9](https://github.com/younho9) diff --git a/narkdown.config.json b/narkdown.config.json index 16cd5c0..6ab6355 100644 --- a/narkdown.config.json +++ b/narkdown.config.json @@ -2,15 +2,12 @@ "exportConfig": { "recursiveExport": true, "createPageDirectory": true, - "addMetadata": false, - "lowerPathname": true, - "lowerFilename": true, - "lineBreak": false + "addMetadata": true, + "appendCreatedTime": true, + "generateSlug": true }, "databaseConfig": { "categoryColumnName": "Category", - "tagsColumnName": "Tags", - "createdTimeColumnName": "Created Time", "statusColumnName": "Status", "currentStatus": "โœ… Completed", "nextStatus": "๐Ÿ–จ Published" diff --git a/requirements.txt b/requirements.txt index 56bf8f8..17bb333 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -narkdown==1.2.3 +narkdown