惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LangChain Blog
C
Check Point Blog
博客园 - Franky
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
V2EX - 技术
V2EX - 技术
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Jina AI
Jina AI
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
H
Hackread – Cybersecurity News, Data Breaches, AI and More
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
G
GRAHAM CLULEY
V
V2EX
The Register - Security
The Register - Security
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
Help Net Security
Help Net Security
大猫的无限游戏
大猫的无限游戏
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
S
Secure Thoughts
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
NISL@THU
NISL@THU
K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
宝玉的分享
宝玉的分享
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
博客园_首页
A
Arctic Wolf

崎径 其镜

Unity CVE-2025-59489 漏洞修复实践(Google Play 合规) 从零配置 VS Code C++ 环境 力扣笔记 Unity 游戏的 Google Play 16 kb页面对齐处理 Unity 升级到 2022 踩坑记录(URP / 黑屏 / HTTP) Android Google Play 16 KB 页面对齐适配指南 iOS 应用开启包外存储访问(文件共享) xlua学习笔记 Lua新知 EFK日志分析系统的搭建 使用贝塞尔曲线实现道具随机飞动效果 震惊,JS不加分号会造成错误!? Linux升级Python Github图床工具 JS使用replace()函数全部替换 JS使用Splice()函数操作数组 当你的程序连接Mysql然后崩溃时 安卓应用闪屏 安卓各渠道SDK接入体验 某微信爬虫工具多开方案 U3D问题总结(七) lua U3D问题总结(六) 优化 U3D问题总结(五) 渲染与光照 U3D问题总结(四) 物理相关 U3D问题总结(三) Unity基础
一文详解Hexo 博客搭建
Anqi Zhao · 2026-04-03 · via 崎径 其镜

前言

捡起了好久没有更新的博客。

在AI 的帮助下,我完成了整个环境的重新搭建。

由于我使用的hexo 框架和版本都比较老了,所以有些地方可能不适应于新版本的主题,在接入时还请注意。

参考视频: https://www.bilibili.com/video/BV1xTgTemEDU/

视频文档: https://xiamu-ssr.github.io/Hexo/2024/06/19/2024-H1/2024-06-19-12-31-52/

准备工作

使用Github Actions 服务,将hexo 部署到 Github Pages。

与参考内容不同的是,我使用了两个仓库来实现。

参考内容中,使用了同一个项目,两个分支。其中一个分支用于提交博客源文件,另一个分支用于存放生成的静态网页文件。

考虑到将博客源文件内容暴露出来会有一定的风险,于是我的方案是使用两个仓库来实现。其中,Private 的仓库用于存放博客源文件,Public 的仓库用于存放页面。

我之前是有hexo 环境的,会和从头开始实现有所区别,在接下来的内容中,我将会分别说明。

关于Github Actions 服务的用量,Public 仓库可以免费使用,但是Private 的仓库会有一定的限制。但是如果只是作为hexo的资源站,免费的额度也是可以覆盖的。

安装并初始化hexo,如果已有hexo环境,可跳过这一步。

npm install -g hexo-cli
hexo init blog
cd blog
npm install

如果是已有hexo环境,在其他地方做过备份的。可以删除node_modules目录和package-lock.json,然后重新安装:

cd blog
npm install

仓库准备

在github上新建两个仓库,一个Private的blog_base,一个Public 的username.github.io;

已有Github Pages 的,可以不用重新创建username.github.io,只创建博客源文件仓库。

Token准备

使用Github Actions ,需要生成Personal access tokens,而且至少要包含repo 权限。把这个Token 配置给Github Action, 它才有权限去执行自动部署。

首先是Token 的创建:

单击头像 -> Settings -> Developer Settings -> Personal access tokens -> Tokens (classic)

这里是所有Tokens的列表,下面我们继续创建:

Generate new token -> Generate new token (classic)

新打开的界面中,我们需要给这个token 命名,随便命名即可,比如blog_base。

在下面的权限列表中,勾选repo,workflow 两项。

记录token的有效期,有效期到期后需要给Github Actions 配置新的token。

完成创建后,去到blog_base 仓库进行配置。首先打开该仓库,点击上方的Settings -> Secrets and variables -> Actions

点击 New repository secret 创建,Name设置为:GH_TOKEN(可随意设置,后面保持一致即可),Secret 粘贴刚才生成出来的token内容,就是一串以ghp_为开头的字符串。

修改_config.yml

为了设置推送的地址,需要在_config.yml 中配置推送地址。这里选择Public 的Github pages 仓库地址:

deploy:
type: git
repo: https://github.com/yourusername/your-repo.git
branch: master

配置Github Actions 工作流

在blog_base 目录创建**.github文件夹,再在.github文件夹下创建workflows文件夹,然后创建deploy.yml**,内容如下:

name: Deploy Hexo to GitHub Pages

on:
push:
branches:
- main # 当推送到 main 分支时触发

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: false # 禁用子模块检查

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Install Dependencies
run: npm install

- name: Install Hexo Git Deployer
run: |
npm install hexo-deployer-git --save
npm install hexo-cli -g

- name: Clean and Generate Static Files
run: |
hexo clean
hexo generate

- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

- name: Deploy to GitHub Pages
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
cd public/
git init
git add -A
git commit -m "Create by workflows"
git branch -M master
git remote add origin https://${{ secrets.GH_TOKEN }}@github.com/yourusername/your-repo.git
git push -f origin master

这里最后一步是将生成的内容,推送到你配置的仓库的master 分支,我的Github Pages就是设置的这个分支。

配置里的node-version 这个参数需要注意。旧版的hexo 使用新版的node 可能会生成失败。我的主题使用的hexo 版本比较老,使用12版本是可以生成的,最新的24 反而无法生成,这里可以按需修改版本。

这个工作流的意思就是,使用ubuntu-latest作为基础环境,然后安装各种依赖,随后hexo generate生成博客网站静态文件夹,最后再推送到设定的仓库和分支。

配置Github Pages

到Github Pages 仓库,点击Settings,设置page来源的分支。

推送并查看是否能够生效。

在这里,介绍一下我的.gitignore文件:

.DS_Store
Thumbs.db
db.json
*.log
public/
.deploy*/
node_modules/

.DS_Store文件和Thumbs.db文件。这两个文件分别是Mac系统和Win系统生成的垃圾。

public 目录存放的是本地生成的静态页面,这个也不必上传。Github Actions 会自动生成。

node_modules 目录一定不能上传,需要排除掉。因为它太大了,不方便版本控制。而且不同平台需求的可能都不同。本地环境和运行Github Actions 的虚拟机环境不可能保证一致的。

其他注意事项

如果你之前是有Github Pages的,需要做好备份,防止文件丢失。

我就出现了CNAME文件和其他文件丢失的情况,这里需要注意。

自定义域名

如果嫌username.github.io 的网址不够优雅,可以注册域名,然后配置解析。

在购买域名后,进行以下设置:

Github 配置

进入Github Pages 仓库,单击Settings 切页。

在左侧边栏点击Pages。

Custom domain 配置为:

www.yourdomin.xxx

然后勾选Enforce HTTPS

域名解析

在域名解析中,做出以下设置:

www  CNAME  yourusername.github.io
@ AAAA 2606:50c0:8003::153
@ AAAA 2606:50c0:8002::153
@ AAAA 2606:50c0:8001::153
@ AAAA 2606:50c0:8000::153
@ A 185.199.111.153
@ A 185.199.110.153
@ A 185.199.108.153

这里参考Github的文档:https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site

创建CNAME

需要在Github Pages 网站的根目录创建CNAME文件,内容是在第一步中配置的www.yourdomin.xxx