GitHub Pages + Hexo创建博客

安装hexo

  1. 安装Node.js
  2. 使用npm安装hexo-cli。
1
npm install -g hexo-cli
  1. 初始化Hexo博客。
1
hexo init blog
  1. 安装node.js依赖包。
1
2
cd blog
npm install

设置git仓库

推送源码

1
2
3
4
5
6
7
8
9
10
11
git init

git config user.name "you"
git config user.email "you@users.noreply.github.com"

git remote add origin git@github.com:you/your_repo.git

git add .
git commit -m "Initial commit"
git branch -M main
git push -u origin main

创建Token

  1. 在GitHub Settings–>Developer settings–>Personal access tokens–>Tokens (classic)–>Generate new tokens (classic)创建一个token用于Github Action。
  2. Note可命名为hexo_token,配置中勾选repoworkflow后生成token。
  3. 将token复制到仓库设置–>Secrets and variables–>Actions–>Repository secrets。

修改_config.yml配置deploy

1
2
3
4
deploy:
type: git
repo: git@github.com:you/you.github.io.git
branch: gh-pages

配置Github Action

  1. \.github新增workflows\deploy.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
48
49
50
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: '24'

- 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.hexo_token }}
run: |
cd public/
git init
git add -A
git commit -m "Create by workflows"
git remote add origin https://${{ secrets.hexo_token }}@github.com/your/your-repo.git
git push origin HEAD:gh-pages -f
  1. node-version需版本一直,node --version查看版本。

Icarus主题美化

  1. 安装Icarus
1
npm install -S hexo-theme-icarus hexo-renderer-inferno

安装完成后等一会生成_config.icarus.yml文件
2. 配置为Icarus主题

1
hexo config theme icarus

开始写作

新建文章

1
hexo new [layout] <title>

启动 Hexo 本地服务器

1
hexo server

清理 Hexo 缓存和静态文件

1
hexo clean
作者

Shana-wen

发布于

2025-12-31

更新于

2026-01-28

许可协议

评论