Hexo + Butterfly 博客搭建指南 🎨
✨ 特别说明 欢迎访问本站 !本博客基于 Hexo 静态框架 + Butterfly 主题构建,兼具简洁美观与强大功能。 📌 本站内容仅供学习交流,不承担因版本差异导致的问题。已适配版本:
Hexo 7.3.0
Butterfly 5.5.0
📑 导航目录
🛠️ 一、下载安装基础运行程序 搭建博客前,需安装以下基础工具:
Git :下载地址 📌 安装时注意勾选“Add Git Bash Here”和“Add to PATH”选项。
Node.js :下载地址 📌 建议选择 LTS 版本,确保环境稳定性。
🔄 切换淘宝镜像加速 1 2 3 npm config set registry http://registry.npm.taobao.org/ npm get registry
🔧 如需切换回官方源:1 npm config set registry https://registry.npmmirror.com/
⚙️ 二、安装 Hexo 🌍 全局安装 Hexo CLI
📦 局部安装(可选)
🔄 升级 Hexo
查看当前版本
🔧 三、Hexo 常用命令 1. 初始化博客 1 2 hexo init blog cd blog && npm install
2. 常用命令组合
组合命令
说明
hexo clean && hexo g && hexo s
清除缓存 → 生成静态文件 → 启动本地服务器(推荐)
hexo clean && hexo g && hexo d
清除缓存 → 生成静态文件 → 部署到远程仓库
hexo clean && hexo g -d
清除缓存后直接生成并部署(简化版)
hexo new "文章标题" && hexo s
创建新文章后立即启动本地服务器预览
hexo clean && hexo g && hexo s -p 5000
清除缓存 → 生成 → 在指定端口(5000)启动服务器
🎨 四、安装与配置 Butterfly 主题 1. 克隆主题仓库 1 git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
2. 安装渲染器 1 npm install hexo-renderer-pug hexo-renderer-stylus --save
3. 启用主题 修改根目录 _config.yml
:
4. 主题配置优化 将主题配置文件 themes/butterfly/_config.yml
移动至根目录并重命名为 _config.butterfly.yml
,便于统一管理。
🧭 五、设置导航菜单 1. 配置菜单项
1 2 3 4 5 6 7 8 menu: 主页: / || fas fa-home 标签: /tags/ || fa fa-tags 分类: /categories/ || fa fa-archive 归档: /archives/ || fa fa-folder-open 友链: /link/ || fa fa-link 关于: /about/ || fas fa-heart 留言板: /comment/ || fa fa-paper-plane
2. 创建菜单页面 使用 Hexo 页面生成命令:
1 2 3 4 5 6 hexo new page tags hexo new page categories hexo new page archives hexo new page link hexo new page about hexo new page comment
3. 友链数据配置 在 source/_data/link.yml
中配置友链信息(示例):1 2 3 4 5 6 7 - class_name: 友情链接 class_desc: 那些人,那些事 link_list: - name: Hexo link: https://hexo.io/zh-tw/ avatar: https://d33wubrfki0l68.cloudfront.net/6657ba50e702d84afb32fe846bed54fba1a77add/827ae/logo.svg descr: 快速、简单且强大的网志框架
4. 文章模板优化 编辑 scaffolds/post.md
可自定义文章 Front Matter:1 2 3 4 5 6 7 8 9 10 11 12 13 --- title: {{ title }}date: {{ date }}description: {{ description }}top_img: {{ top_img }}sticky: {{ sticky }}categories: - tags: - cover: {{ cover }}updated: {{ date }}---
✨ 六、动态特效与功能增强 1. 动态彩带效果 1 2 3 canvas_fluttering_ribbon: enable: true mobile: false
2. 鼠标点击特效 1 2 3 4 fireworks: enable: false zIndex: 9999 mobile: false
3. 页面加载动画 1 2 3 preloader: enable: true source: 1
📊 七、数据统计与搜索 1. 字数统计插件 1 npm install hexo-wordcount --save or yarn add hexo-wordcount
配置主题文件:1 2 3 4 5 wordcount: enable: true post_wordcount: true min2read: true total_wordcount: true
2. 本地搜索功能
1 npm install hexo-generator-search --save
1 2 3 4 5 search: path: search.xml field: post format: html limit: 10000
在 _config.butterfly.yml
主题配置中启用
1 2 3 use: local_search local_search: enable: true
🖼️ 八、随机封面图 API 1. 创建随机图脚本
在 themes/butterfly/scripts/
下创建 random_img.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 'use strict' const IMG_TEST_REG = /\.(png|jpe?g|gif|svg|webp)(\?.*)?$/ ;hexo.extend .filter .register ('before_post_render' , function (data ) { const { config } = this ; const { post_asset_folder } = config; if (post_asset_folder) { processImagePath (data, 'top_img' ); processImagePath (data, 'cover' ); } if (data.cover === false ) { data.randomcover = getRandomCover (); } else { data.cover = data.cover || getRandomCover (); } return data; }, 0 ); function processImagePath (data, key ) { const image = data[key]; if (image && image.indexOf ('/' ) === -1 && IMG_TEST_REG .test (image)) { data[key] = data.path + image; } } function getRandomCover ( ) { const theme = hexo.theme .config ; let cover; let num; const defaultCovers = theme.cover && theme.cover .default_cover ; if (defaultCovers) { if (!Array .isArray (defaultCovers)) { cover = defaultCovers; } else { num = Math .floor (Math .random () * defaultCovers.length ); cover = defaultCovers[num]; } } else { cover = theme.default_top_img || 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' ; } if (theme.cover && theme.cover .suffix ) { const randomValue = Math .ceil (Math .random () * 10000 ); if (theme.cover .suffix === 1 ) { cover += `?${randomValue} ` ; } else if (theme.cover .suffix === 2 ) { cover += `&${randomValue} ` ; } } return cover; }
2. 配置封面设置
在 _config.butterfly.yml
主题配置中修改
1 2 3 4 5 6 7 8 cover: index_enable: true aside_enable: true archives_enable: true position: both suffix: 1 default_cover: - https://api.mobufan.eu.org:666
💫 九、副标题与侧边栏优化 1. 动态副标题设置 _config.butterfly.yml
1 2 3 4 5 6 7 subtitle: enable: true effect: true source: 1 sub: - 你在抱怨什么呢 - 为明天到来的事,说人生像是没有意义
2. 侧边栏配置 _config.butterfly.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 aside: enable: true hide: false button: true mobile: true position: right display: archive: true tag: true category: true card_author: enable: true description: button: enable: true icon: fab fa-github text: GitHub link: https://github.com/meimolihan card_announcement: enable: true content: <center><b>--- 主域名 ---<br><a href="https://www.meimolihan.eu.org" title="此线路部署于Vercel" class="anno_content"><font color="#5ea6e5">www.meimolihan.eu.org</font></a> | <a href="https://meimolihan.eu.org" title="此线路部署于Vercel" class="anno_content"><font color="#5ea6e5">meimolihan.eu.org</font></a></b></center>
🔗 十、永久链接生成 插件链接: xo-abbrlink
1. 安装 abbrlink 插件 1 npm install hexo-abbrlink --save
2. 配置永久链接 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 permalink_defaults: permalink: posts/:abbrlink.html abbrlink: alg: crc32 rep: hex drafts: false auto_category: enable: true depth: 3 over_write: false auto_title: false auto_date: false force: false pretty_urls: trailing_index: true trailing_html: true
🟡 警告:谨慎修改,不然部署到 Vercel 文章无法解析
3. 配置说明 crc16 1 2 3 4 5 crc16 & hex http :crc16 & dec http :
crc32 1 2 3 4 5 crc32 & hex http :crc32 & dec http :
🔄 十一、博客迁移指南 🖥️ 新电脑环境配置
Git :下载地址 📌 安装时注意勾选“Add Git Bash Here”和“Add to PATH”选项。
Node.js :下载地址 📌 建议选择 LTS 版本,确保环境稳定性。
关闭 SSL 严格模式(解决证书问题): 1 npm set strict-ssl false
📦 迁移项目文件
1 2 3 4 5 6 7 - `_config.yml` - `_config.butterfly.yml` - `themes/` - `source /` - `scaffolds/` - `package.json` - `.gitignore`
🔑 SSH密钥重新配置 1 2 3 4 git config --global user.name "YourName" git config --global user.email "your@email.com" ssh-keygen -t rsa -C "your@email.com"
🚀 部署测试 1 2 3 4 npm install hexo-cli -g npm install npm install hexo-deployer-git --save hexo clean; hexo g; hexo s
📦 十二、插件列表与升级指南 🔄 全局安装/升级 Hexo 及相关工具常用命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 npm i hexo-cli -g npm install -g npm-check npm install -g npm-upgrade npm-check npm-upgrade npm update -g npm update --save
🧩 常用插件列表
插件名称
功能描述
安装命令
hexo-wordcount
字数统计
npm install hexo-wordcount --save
hexo-abbrlink
永久链接
npm install hexo-abbrlink --save
hexo-generator-search
本地搜索
npm install hexo-generator-search --save
hexo-deployer-git
Git部署
npm install hexo-deployer-git --save
📝 更多插件请参考原文中的完整插件表格,按需安装使用。
🎉 恭喜! 您已完成 Hexo 博客的搭建与美化。如有问题,欢迎在评论区留言交流。
Hexo + Butterfly 博客搭建指南 🎨