Note-53156-34

Token ID: 1

ERC-721 1 Transfers

Metadata

{
  "title": "Hexo和Notion的神级联动",
  "tags": [
    "post",
    "hexo",
    "notion"
  ],
  "sources": [
    "xlog"
  ],
  "external_urls": [
    "https://xlog.wangyunzi.com/64"
  ],
  "date_published": "2023-04-17T07:41:34.388Z",
  "content": "---\r\nslug: \"64\"\r\ncategories: blog\r\ndescription: 前几天还在想着如何真正实现随时随地编辑hexo博客,这不,现在就有大佬实现这个目标啦!\r\ntags:\r\n  - hexo\r\n  - notion\r\nstatus: 已发布\r\ntype: post\r\nfilename: \"64\"\r\ntitle: Hexo和Notion的神级联动\r\nid: 436ece40-98cc-4d32-8df4-54054f992188\r\ncreated: 2023-04-17T06:01:00.000Z\r\nupdated: 2023-04-17T07:30:00.000Z\r\n---\r\n\r\n### 完成目标\r\n\r\n- notion 文章转化为 markdown 格式\r\n- 在 notion 上写博客\r\n- 发布 notion 文章到 hexo\r\n\r\n### 项目起源\r\n\r\n- 初代:项目由[@](https://github.com/mohuishou/notion-blog-actions)[**Mo Huishou**](https://github.com/mohuishou/notion-blog-actions) 最初创建使用,但只支持阿里云图床,且不支持文章修改。\r\n- 目前:由[**@Doradx**](https://github.com/Doradx/notion2markdown-action) 大佬改造后支持多种图床,且支持文章修改\r\n\r\n### 项目教程\r\n\r\n- [**Notion-Hexo 联动发布博客 - 自动化部署方案**](https://blog.cuger.cn/p/634642fd/)\r\n- [**使用 Notion Database 管理静态博客文章**](https://lailin.xyz/post/notion-markdown-blog.html)\r\n\r\n### 我的个人流程\r\n\r\n上面的教程已经够完整了,但是我喜欢自己写一写自己在这个过程中自己操作上的失误,可以选择性浏览。\r\n\r\n1. 打开下面链接创建一个 notion 机器人,获取`Secrets`。\r\n\r\n[bookmark](https://www.notion.so/my-integrations)\r\n\r\n1. 复制模板[blog-template](/8d102b64643c4060a7fd3228fb81d043)。\r\n2. 授权数据库,打开复制过的模板,点击右上角三个点,点击下面的添加 connection,加上刚刚的机器人。\r\n3. 在博客仓库  `settings/secrets/actions`中添加环境变量,分别是`NOTION_DATABASE_ID`, `NOTION_TOKEN`和  `PICBED_CONFIG`。下面是大佬的原文:\r\n\r\n![](https://blog.wangyunzi.com/2023/123a424123e9d1abfbcb8c03628df90a.png)\r\n\r\n1. 在博客中目录`.github/workflows` 新建`deploy.yml`和`notion_sync.yml` 这两个我的代码如下:\r\n\r\n```yaml\r\nname: Automatic deployment\r\n\r\non:\r\n  push:\r\n    branches: master\r\n    paths:\r\n      - \"source/**\"\r\n      - \"**.yml\"\r\n  workflow_dispatch:\r\n  workflow_call:\r\n\r\nenv:\r\n  GIT_USER: wangyunzi\r\n  GIT_EMAIL: [email protected]\r\n\r\njobs:\r\n  build:\r\n    name: Ubuntu and node ${{ matrix.node_version }} and ${{ matrix.os }}\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        os: [ubuntu-latest]\r\n        node_version: [16.19.1]\r\n\r\n    steps:\r\n      - name: Checkout blog and theme\r\n        uses: actions/checkout@v3\r\n        with:\r\n          submodules: \"recursive\"\r\n      - name: Use Node.js ${{ matrix.node_version }}\r\n        uses: actions/setup-node@v3\r\n        with:\r\n          node-version: ${{ matrix.node_version }}\r\n      - name: Install dependencies\r\n        run: |\r\n          git pull\r\n      - name: Depoly\r\n        run: |\r\n          git ls-files -z | while read -d '' path; do touch -d \"$(git log -1 --format=\"@%ct\" \"$path\")\" \"$path\"; done\r\n          npm install\r\n          npx hexo clean\r\n          npx hexo douban\r\n          npx hexo g\r\n      - name: Commit & Push\r\n        uses: stefanzweifel/git-auto-commit-action@v4\r\n        with:\r\n          commit_message: Automatic deployment.\r\n```\r\n\r\n```yaml\r\nname: Automatic sync pages from notion\r\n\r\non:\r\n  #   push:\r\n  #     branches: master\r\n  workflow_dispatch:\r\n  schedule:\r\n    - cron: \"5 */1 * * *\"\r\n\r\njobs:\r\n  notionSyncTask:\r\n    name: Ubuntu and node ${{ matrix.node_version }} and ${{ matrix.os }}\r\n    runs-on: ubuntu-latest\r\n    strategy:\r\n      matrix:\r\n        os: [ubuntu-latest]\r\n        node_version: [16.x]\r\n    outputs:\r\n      HAS_CHANGES: ${{ steps.checkStep.outputs.HAS_CHANGES }}\r\n\r\n    steps:\r\n      - name: Checkout\r\n        uses: actions/checkout@v3\r\n      - name: Use Node.js ${{ matrix.node_version }}\r\n        uses: actions/setup-node@v3\r\n        with:\r\n          node-version: ${{ matrix.node_version }}\r\n      - name: Convert notion to markdown\r\n        uses: Doradx/notion2markdown-action@latest\r\n        with:\r\n          notion_secret: ${{ secrets.NOTION_TOKEN }} # NOTION授权码\r\n          database_id: ${{ secrets.NOTION_DATABASE_ID }} # Dataset ID\r\n          migrate_image: true\r\n          picBedConfig: ${{ secrets.PICBED_CONFIG}} # picBed的配置,JSON格式,建议为minify JSON, 否则可能报错. 不同图床的配置可参考:https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#picbed\r\n          page_output_dir: \"source\" # page 类文章的输出目录,例如about。\r\n          post_output_dir: \"source/_posts/notion\" # post 的输出目录,切记当clean_unpublished_post为true时,勿设置为 'source/_posts', 可能会删除你原目录下的文章!!!\r\n          clean_unpublished_post: true # 是否清除未发表的文章,例如之前发表了,你又在notion中给移到草稿箱了.\r\n      - name: Check if there is anything changed\r\n        id: checkStep\r\n        run: |\r\n          if [[ -n \"$(git status --porcelain)\" ]]; then\r\n            echo \"HAS_CHANGES=true\" >> $GITHUB_OUTPUT;\r\n            echo \"Updates available & redeployment required.\"\r\n          else\r\n            echo \"HAS_CHANGES=false\" >> $GITHUB_OUTPUT;\r\n            echo \"Nothing to commit & deploy.\"\r\n          fi\r\n      - name: Commit & Push\r\n        uses: stefanzweifel/git-auto-commit-action@v4\r\n        with:\r\n          commit_message: Automatic sync from notion.\r\n  callDepolyTask:\r\n    name: Call the depoly workflow\r\n    needs: notionSyncTask\r\n    if: ${{ needs.notionSyncTask.outputs.HAS_CHANGES=='true' }}\r\n    uses: wangyunzi/Annie/.github/workflows/hexo_deploy.yml@master # 根据自身Github地址修改即可\r\n```\r\n\r\n1. 检查上面两个代码的`node`版本,改成和自己一样的即可。(ps:没有改的话就会出现一点小问题,譬如我)\r\n2. 需要发表的文章放置在待发布这一栏,如果需要及时看到效果手动运行 action,源代码默认是 1 个小时检查一次是否有文章需要发布。\r\n\r\n> **这次能够完美完成完全是依靠**[**@Doradx**](https://blog.cuger.cn/)**大佬的倾情帮助,写这篇文章不仅是感谢他改造这样便捷的项目,也是为了感谢大佬的不辞辛苦,一遍遍的指导我完成这些配置。**\r\n",
  "attributes": [
    {
      "value": "64",
      "trait_type": "xlog_slug"
    }
  ]
}