透过 Github Action 自动部署 Hexo 博客
558 字
3 分钟
透过 Github Action 自动部署 Hexo 博客
- 1部署Github Page的错误解决
- 2透过 Github Action 自动部署 Hexo 博客本文
- 3我说Cloudflare神了
- 4记一次Cloudflare盗号

嘛…结果兜兜转转还是回到 Action 来了…最近经历的事情真多啊,这里依然是我的私人小空间 ww
总而言之先把该有的内容写好!
步骤
1. 创建仓库 Repo
- 私人库 A,设置为 Private,这就是工程博客仓库
- 公开库 B,设置为 Public,用于 Github Pages 发布(你有 Github Pro 可以在 private 状态下发布)
2. 设置公私钥
-
执行命令获得一对 ssh-key:
Terminal window ssh-keygen -t rsa -b 4096 -C "hexo-deploy" -f hexo_deploy_key -
填写全部默认 enter 就行
-
此时你的根目录应该拥有
hexo-deploy_key以及hexo-deploy_key.pub -
设置公钥
- 进入 Github 公开库 B(通常为博客的 xxx.github.io),
settings→Deploy keys→Add deploy key - 填写
hexo_deploy_key.pub中的内容(title项随意) - 记得勾选
Allow write access
- 进入 Github 公开库 B(通常为博客的 xxx.github.io),
-
设置私钥
- 进入 Github 私人库 A,
settings→Secrets and variables→New repository secret - 填写
hexo_deploy_key的内容(Name项随意)
- 进入 Github 私人库 A,
3. 配置 Github Action
-
创建文件
.github/workflows/deploy.yml(若文件夹缺失则创建补全) -
填写以下内容:
name: Hexo Deployon:push:branches:- main # 或者是 master,取决于你的默认分支名jobs:build:runs-on: ubuntu-lateststeps:- name: Checkout sourceuses: actions/checkout@v3with:# 如果你的主题是作为 git submodule 存在的,需要开启这个# 具体取决于你的主题文件夹内是否存在.git文件夹,推荐删掉.git后false掉,以免莫名其妙的特性submodules: false- name: Setup Node.jsuses: actions/setup-node@v3with:node-version: "24" # Node版本,目前24是LTScache: "npm"- name: Install dependenciesrun: npm install- name: Build Hexorun: npx hexo generate- name: Deploy to GitHub Pagesuses: peaceiris/actions-gh-pages@v3with:deploy_key: ${{ secrets.HEXO_DEPLOY_PRI }} # 这里对应你在私有仓库设置的 Secret 名字external_repository: username/username.github.io # 修改为你接收静态页面的公有仓库: 用户名/仓库名publish_branch: main # 公开库B的branch,取决于你是main还是masterpublish_dir: ./public # 将./public文件夹推送过去,一般不用管commit_message: ${{ github.event.head_commit.message }}user_name: "github-actions[bot]"user_email: "github-actions[bot]@users.noreply.github.com" -
接下来随便
hexo new一个 Pages 什么的,用 git 推送过去就可以享受自动更新了!
后记
结果也确实有段时间没碰博客了嘛……(其实很久很久…)
总而言之我回来诈尸一下,未来或许会有点 oc 内容呢?谁知道呢
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
相关文章智能推荐
1
部署Github Page的错误解决
技术在配置DNS和Pages时遇到的两个怪问题以及解决方法x 1. *InvalidCNAMEError* 2. *NotServedByPagesError* 2.5? 顺带的-无法访问页面:*ERR_CONNECTION_CLOSED*
2
迁移完了
随笔Astro 或许比 Hexo / WordPress 更对!
3
记一次Cloudflare盗号
技术O——M——G,被盗号了…… 所以索性记录一下(点头)
4
我说Cloudflare神了
技术Github Action!Switch!Cloudflare Pages!
5
记录一下自用的Agent.md
AI最近感觉codex脸色对了(不是),总之好像调教的不错,所以分享一下…有多少人看到呢…就不知道了,但这种东西,传到git不太好吧x,纯markdown的repo,放到曾经也是拿不出手的感觉,而且有点敏感信息
随机文章随机推荐



























