Hexo + Butterfly 博客搭建指南
准备
用 Hexo 框架可以快速搭建一个博客网站,再配合 butterfly 主题可以搭建出较为好看的页面,需遵循它的配置。
安装 node、git、vscode可以本站查找安装攻略
创建博客
桌面新建文件夹 blog,进入根目录 cmd 打开终端,安装 hexo 脚手架:
1 | hexo version # 查看版本 |
初始化项目:
1 | hexo init |
等待完成,生成本地页面:
1 | hexo s |
浏览器访问 http://localhost:4000/ 即可看到本地版。
部署博客
GitHub
去 Github 新建仓库 luckyNwa.github.io,必须这个格式,第一个名称改自己的 GitHub 名称。
打开 _config.yml 最后一行改成下面:
1 | # Deployment |
在 blog 文件夹路径 cmd 打开终端,安装自动部署发布工具:
1 | npm install hexo-deployer-git --save |
生成页面并上传到 GitHub:
1 | hexo g # 生成静态文件 |
访问 https://luckynwa.github.io/ (需要等它部署几分钟)。
Vercel
官网 https://vercel.com/ 用 GitHub 登录即可。
点击 new 一个项目,找到刚刚那个博客导入,点部署,它会分配一个二级域名免费用,也可以绑定自己的国内域名。
示例地址:https://lucky-blog.vercel.app/
安装主题
常用指令
1 | hexo cl # 清除缓存 |
package.json 脚本说明
1 | { |
iNode18/clean→ 安装依赖、删除依赖dev/server→ 运行,同时删除缓存重新生成build→ 打包deploy→ 推送到 GitHub
Butterfly 主题
- 中文文档:https://butterfly.js.org/ (最好科学上网)
- 开源地址:https://github.com/jerryc127/hexo-theme-butterfly
安装主题
1 | git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly |
打开 _config.yml 修改主题:
1 | theme: butterfly |
重要:
_config.yml同级别创建_config.butterfly.yml,把themes/butterfly文件夹下的 config 内容复制进去,删除_config.landscape.yml。
安装渲染器
1 | npm install hexo-renderer-pug hexo-renderer-stylus --save |
URL 优化
安装 abbrlink 插件:
1 | npm install hexo-abbrlink --save |
_config.yml 找到 permalink 修改:
1 | # 原始 |
本地搜索
安装搜索插件:
1 | npm i hexo-generator-search --save |
_config.yml 下新增:
1 | # 本地搜索 |
主题配置 _config.butterfly.yml 中,local_search 下两个值都设为 true。
问题
VS Code 中不能启动项目
1 | get-ExecutionPolicy # 必须是 RemoteSigned 才行 |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 小维的博客园!

