hexo创建并免费自动化部署
环境准备
1. 安装 Node.js
- 下载 Node.js v20
- 切换 npm 镜像源(推荐淘宝源):
1
2npm i -g nrm
nrm use taobao
2. 安装 Hexo
- 全局安装 Hexo CLI:
1
npm i hexo-cli -g
- 初始化项目并安装依赖:
1
2
3hexo init blog
cd blog
npm install - 启动本地服务:
1
hexo server
3. 安装 Git 并配置
- 下载 Git
- 配置用户名和邮箱:
1
2git config --global user.name "your name"
git config --global user.email "your email" - 初始化仓库并推送到 GitHub:
1
2
3
4
5
6cd blogs
git init
git remote add origin https://github.com/cxvh/blog.git
git add .
git commit -m "first commit"
git push -u origin main
自动化部署
1. 部署到 Vercel(推荐,完全免费)
- 使用 GitHub 登录 Vercel
- 新建项目,选择要部署的仓库
- 等待构建完成即可访问,可自定义域名
- 可选自定义配置(Settings):
- Build & Development Settings
- Framework Preset:
hexo
- Build Command:
hexo algolia && hexo generate
(Override 开启) - Output Directory:
public
(Override 开启)
- Framework Preset:
- Node.js Version: 选择
20.x
- Build & Development Settings
- 代码提交后自动触发构建:
1
git push origin main
2. 部署到 GitHub Pages
- 创建
cxvh.github.io
仓库 - 安装部署插件:
1
npm install hexo-deployer-git --save
- 修改项目根目录下
_config.yml
:1
2
3
4deploy:
type: git
repo: https://github.com/cxvh/cxvh.github.io.git
branch: main - 在
package.json
的scripts
添加:1
"deploy": "hexo deploy"
- 构建并部署:
1
2hexo generate
hexo deploy - 访问:https://cxvh.github.io
Hexo 常用命令
1 | # 创建文章 |
主题与插件
安装主题
- 安装 Butterfly 主题:
1
npm i hexo-theme-butterfly
- 修改
_config.yml
:1
theme: butterfly
站点地图与搜索引擎收录
- 安装插件:
1
npm install hexo-generator-sitemap hexo-generator-baidu-sitemap --save
- 生成地图并部署:
1
2hexo generate
hexo deploy - 生成的
sitemap.xml
和baidusitemap.xml
位于public
目录 - 提交收录入口:百度搜索提交入口
配置建议
多标签/多分类
1 | tags: [a, b, c] |
基本信息(建议完整填写)
1 | title: your title |
Feed 配置
- 参考 hexo-generator-feed
1
2
3
4feed:
type: atom
path: atom.xml
limit: 0
文件命名规范
- 文件名避免使用 HTML 字符实体(如:
&
、<
、>
等),否则sitemap.xml
和baidusitemap.xml
可能无法解析 - 参考:字符实体 HTML ISO-8859-1
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 BARAN的小站🔥🔥🔥!