前言
Hexo 默认的主题比较简单,不够美观。Butterfly 是一个功能强大、设计精美的 Hexo 主题,拥有丰富的功能和良好的用户体验。
本教程将介绍如何安装和配置 Butterfly 主题。
安装 Butterfly 主题
1. 下载主题
在博客根目录下执行:
1 | git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly |
2. 安装依赖
Butterfly 主题需要安装渲染器插件:
1 | npm install hexo-renderer-pug hexo-renderer-stylus --save |
3. 启用主题
修改博客根目录下的 _config.yml 文件:
1 | theme: butterfly |
4. 复制主题配置文件
在博客根目录下执行:
1 | cp themes/butterfly/_config.yml _config.butterfly.yml |
这样可以在不修改主题源码的情况下自定义配置。
基础配置
1. 网站信息
编辑 _config.yml:
1 | title: 我的博客 |
2. 导航栏配置
编辑 _config.butterfly.yml:
1 | nav: |
3. 代码块配置
1 | code_blocks: |
4. 封面图片
1 | cover: |
创建页面
1. 创建分类页
1 | hexo new page categories |
编辑 source/categories/index.md:
1 | --- |
2. 创建标签页
1 | hexo new page tags |
编辑 source/tags/index.md:
1 | --- |
3. 创建关于页
1 | hexo new page about |
编辑 source/about/index.md:
1 | --- |
文章配置
1. Front-matter
文章开头的配置区域:
1 | --- |
2. 摘要
在文章中添加 <!-- more -->,前面的内容将作为摘要显示在首页。
1 | 这是文章的摘要内容... |
侧边栏配置
1. 启用侧边栏
1 | aside: |
2. 卡片配置
1 | aside: |
评论系统
Butterfly 支持多种评论系统,这里以 Gitalk 为例:
1. 申请 GitHub OAuth App
- 访问 https://github.com/settings/developers
- 点击 “New OAuth App”
- 填写信息:
- Application name: 博客评论
- Homepage URL: https://yourname.github.io
- Application description: 博客评论系统
- Authorization callback URL: https://yourname.github.io
- 创建后获取 Client ID 和 Client Secret
2. 配置 Gitalk
编辑 _config.butterfly.yml:
1 | comments: |
搜索功能
1. 安装搜索插件
1 | npm install hexo-generator-searchdb --save |
2. 配置搜索
编辑 _config.yml:
1 | search: |
编辑 _config.butterfly.yml:
1 | search: |
图片处理
1. 图片资源文件夹
在 _config.yml 中启用:
1 | post_asset_folder: true |
这样创建文章时会自动创建同名文件夹,用于存放图片。
2. 引用图片
在文章中使用相对路径引用图片:
1 |  |
自定义 CSS
如果需要自定义样式,可以在 source/css/ 目录下创建 custom.css:
1 | /* 自定义样式 */ |
然后在 _config.butterfly.yml 中引入:
1 | inject: |
常见问题
Q: 主题没有生效?
A: 检查 _config.yml 中的 theme 是否设置为 butterfly,并执行 hexo clean && hexo g。
Q: 如何更新主题?
A: 进入主题目录执行 git pull。
Q: 如何自定义主题颜色?
A: 在 _config.butterfly.yml 中配置 theme_color。
Q: 如何添加社交链接?
A: 在 _config.butterfly.yml 的 social 部分添加。
下一步
恭喜你,已经配置好了 Butterfly 主题!
接下来的教程将介绍:
- Hexo博客GitHub Actions自动部署教程 - 实现自动化部署
继续学习,让你的博客更加完善吧!






