完成目标
- notion 文章转化为 markdown 格式
- 在 notion 上写博客
- 发布 notion 文章到 hexo
项目起源
项目教程
我的个人流程
上面的教程已经够完整了,但是我喜欢自己写一写自己在这个过程中自己操作上的失误,可以选择性浏览。
- 打开下面链接创建一个 notion 机器人,获取
Secrets
。
- 复制模板Untitled 。
- 授权数据库,打开复制过的模板,点击右上角三个点,点击下面的添加 connection,加上刚刚的机器人。
- 在博客仓库
settings/secrets/actions
中添加环境变量,分别是NOTION_DATABASE_ID
, NOTION_TOKEN
和 PICBED_CONFIG
。下面是大佬的原文:

- 在博客中目录
.github/workflows
新建deploy.yml
和notion_sync.yml
这两个我的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| name: Automatic deployment
on: push: branches: master paths: - "source/**" - "**.yml" workflow_dispatch: workflow_call:
env: GIT_USER: wangyunzi GIT_EMAIL: xueq695@gmail.com
jobs: build: name: Ubuntu and node ${{ matrix.node_version }} and ${{ matrix.os }} runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest] node_version: [16.19.1]
steps: - name: Checkout blog and theme uses: actions/checkout@v3 with: submodules: "recursive" - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} - name: Install dependencies run: | git pull - name: Depoly run: | git ls-files -z | while read -d '' path; do touch -d "$(git log -1 --format="@%ct" "$path")" "$path"; done npm install npx hexo clean npx hexo douban npx hexo g - name: Commit & Push uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: Automatic deployment.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| name: Automatic sync pages from notion
on: workflow_dispatch: schedule: - cron: "5 */1 * * *"
jobs: notionSyncTask: name: Ubuntu and node ${{ matrix.node_version }} and ${{ matrix.os }} runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest] node_version: [16.x] outputs: HAS_CHANGES: ${{ steps.checkStep.outputs.HAS_CHANGES }}
steps: - name: Checkout uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node_version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} - name: Convert notion to markdown uses: Doradx/notion2markdown-action@latest with: notion_secret: ${{ secrets.NOTION_TOKEN }} database_id: ${{ secrets.NOTION_DATABASE_ID }} migrate_image: true picBedConfig: ${{ secrets.PICBED_CONFIG}} page_output_dir: "source" post_output_dir: "source/_posts/notion" clean_unpublished_post: true - name: Check if there is anything changed id: checkStep run: | if [[ -n "$(git status --porcelain)" ]]; then echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT; echo "Updates available & redeployment required." else echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT; echo "Nothing to commit & deploy." fi - name: Commit & Push uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: Automatic sync from notion. callDepolyTask: name: Call the depoly workflow needs: notionSyncTask if: ${{ needs.notionSyncTask.outputs.HAS_CHANGES=='true' }} uses: wangyunzi/Annie/.github/workflows/hexo_deploy.yml@master
|
- 检查上面两个代码的
node
版本,改成和自己一样的即可。(ps:没有改的话就会出现一点小问题,譬如我) - 需要发表的文章放置在待发布这一栏,如果需要及时看到效果手动运行 action,源代码默认是 1 个小时检查一次是否有文章需要发布。
这次能够完美完成完全是依靠@Doradx大佬的倾情帮助,写这篇文章不仅是感谢他改造这样便捷的项目,也是为了感谢大佬的不辞辛苦,一遍遍的指导我完成这些配置。