用 Node.js + Hexo + GitHub Pages,无需服务器,无需域名费用 适合完全零基础的新手,手把手教学
yourname)、邮箱、密码| 软件 | 作用 | 下载地址 | 安装说明 |
|---|---|---|---|
| Node.js | Hexo 运行环境 | nodejs.org | 下载 LTS 版本,一路“下一步” |
| Git | 版本控制和部署 | git-scm.com | 下载 Windows 版本,默认安装 |
打开 Git Bash(安装 Git 后会在右键菜单出现),输入:
node -v # 显示版本号如 v18.18.0 即成功
git --version # 显示版本号如 git 2.42.0 即成功
npm install -g hexo-cli
# 创建博客文件夹(名字自取)
hexo init myblog
# 进入博客目录
cd myblog
# 安装依赖
npm install
hexo g # 生成静态文件
hexo s # 启动本地服务器
打开浏览器访问 http://localhost:4000,看到博客首页即成功
按 Ctrl + C 可停止预览
以广受欢迎的 NexT 主题 为例:
git clone https://github.com/theme-next/hexo-theme-next themes/next
编辑博客根目录的 _config.yml 文件:
theme: next
hexo clean && hexo g && hexo s
刷新 http://localhost:4000 查看新主题
你的用户名.github.io
(例如用户名为 yourname,就填 yourname.github.io)npm install hexo-deployer-git --save
编辑博客根目录 _config.yml,修改 deploy 部分:
deploy:
type: git
repo: https://github.com/你的用户名/你的用户名.github.io.git
branch: main # 或 master,看你的仓库默认分支
hexo clean && hexo g -d
https://你的用户名.github.io
等待 2-5 分钟,就能看到博客上线了!🎉
bbroot.com、de5.netmyblog.bbroot.com在 DNSHe 后台添加 4 条 A 记录:
| 记录类型 | 主机名 | 记录值 |
|---|---|---|
| A | @ | 185.199.108.153 |
| A | @ | 185.199.109.153 |
| A | @ | 185.199.110.153 |
| A | @ | 185.199.111.153 |
(可选)添加 CNAME 让 www 也能访问:
| 记录类型 | 主机名 | 记录值 |
|---|---|---|
| CNAME | www | 你的用户名.github.io |
myblog.bbroot.com)cd myblog
echo "你的域名" > source/CNAME
git add .
git commit -m "添加 CNAME 文件"
git push
cd myblog
hexo new "文章标题"
编辑 source/_posts/文章标题.md
hexo clean && hexo g -d
| 命令 | 作用 |
|---|---|
hexo s |
本地预览 |
hexo clean |
清理缓存 |
hexo g |
生成静态文件 |
hexo d |
部署上线 |
hexo new "标题" |
新建文章 |
hexo new page "名称" |
新建独立页面 |
Ctrl + F5 强制刷新source/CNAME 文件是否存在你的域名(不要加 http://)git push 提示权限错误.nojekyll 文件是否存在_config.yml 里冒号后面必须加空格source/ 和 _config.yml 是最重要的文件按照本指南,你已经拥有:
现在开始写你的第一篇文章吧! 🚀