把 hexo 部署在 Github Pages 中

环境准备

nodejs

下载链接: https://nodejs.org/zh-cn/download

linux

划到最下方选择linux和架构下载tzr.gz压缩文件

1
2
$ tar -xvf node.tar.gz
$ sudo mv node /opt/

在文件.bashrc中添加

1
export $PATH="/opt/node/bin:$PATH"
1
$ source .bashrc

window

划到最下方选择window和架构下载msl文件
运行msl安装完成

npm

npm默认使用的镜像是国外的
所以需要切换镜像,除非你有代理
你可以进入cnpm官网来查看各种方法来使用这个镜像
我一般都是直接修改镜像

1
$ npm config set registry https://registry.npmmirror.com

hexo

安装hexo

1
$ npm i -g hexo

git

ubuntu/debian

1
$ sudo apt install git

window

下载链接: https://git-scm.cn/install/window
选择跟系统架构相同的下载独立安装程序exe
安装时记得勾选Use bundled Openssh

创建项目

window 推荐使用 PowerShell

1
2
3
$ hexo init hexo #创建hexo项目
$ cd hexo
$ npm i

文章路径 source/_posts

  • 创建文章可以在文章目录创建md文件
  • 还有一种使用 hexo new 文章名 就会在文章路径创建md文件
    这两种方法都一样,没有区别

运行

1
2
$ hexo g #生成静态文件
$ hexo s #运行服务 ctrl+c停止

Github Pages 部署

ssh配置

1
2
3
4
5
$ ssh-keygen -t rsa -b 4096 -C "的邮箱"
# ssh密钥名称是随机的
$ cat %USERPROFILE%\.ssh\id_xx.pud #window的
$ cat ~/.ssh/id_xx.pub #linux的
# 复制命令的输出

打开github注册/登陆
创建仓库 复制仓库链接https://hexo.io/themes/

  • -> New repository -> Repository name填仓库名称 -> Create repository(绿色按钮)
    创建好仓库就先摆这
    在github主页点击你的头像
    settings -> SSH and GPS keys -> New SSH keys -> Title随便填 -> Key 剪贴你复制

设置好运行:

1
$ ssh -T [email protected]

输入yes
如果输出有你的用户名,就是key配置成功

hexo 配置

进入项目修改_config.yml

了解

title网站标题
author作者
language语言 中文填 zh-CN
url填域名 https://xx.xx
theme主题

需要修改的

title 改成你想要的标题
author修改成你的名字
url填你的域名
deploy字典中
typegit
repository[email protected]:github用户名/仓库名.git
branchmain
message填个git提交信息 这个可要可不要
实例:

1
2
3
4
5
6
7
8
9
10
11
12
title: KongQi Blog
...
author: KongQi
languagep: zh-CN
...
url: https://kongqi-air.top
...
deploy:
type: git
repository: [email protected]:air459/hexo.git
branch: main
message: "aaaaaa"

提交

1
2
3
$ npm i --save hexo-deployer-git
$ hexo g
$ hexo d #提交

以后你在次提交只要运行

1
2
$ hexo g
$ hexo d

域名

DNS记录

类型 名称 目标
CNAME @ 用户名.github.com

@可以替换子域名

github

进入你刚才创建的新仓库
settings -> Pages -> branch设置成main / -> Custom domain -> 你的域名 -> save
等待github检查域名
域名绑定成功

进阶

主题配置

怎么查找主题

安装主题

hexo themes 网站查找你看得上的主题
点击标题

每个主题的安装方法都有点不同
一般都是
下载主题到themes 文件夹中
然后在_config.yml文件中找到theme: 后面跟上你主题文件夹名称

评论

我以utteranc为主
安装点我 —> install -> 授权
进入utteranc.es
找到repo填写你 用户名/仓库名
其他保持默认
Theme这个可以修改评论的主题
复制Enable Utterances里面的script标签
script标签放在md文档的最后面


把 hexo 部署在 Github Pages 中
https://kongqi-air.top/2026/02/22/hexo-serve/
作者
Kongqi
发布于
2026年2月22日
许可协议