博客主题已更新至3.8.4
本文主要用于记录及分享博主在使用butterfly主题时所使用的功能及涉及到的部分修改;
一些直接修改主题配置文件的功能,请移步Hexo-theme-butterfly开源仓库,参阅官方文档,这里就不做赘述。
此文不涉及源码的修改,源码修改部分请参照Hexo-Butterfly主题修改记录-2
markdown文件最上方以---
分隔的区域
---
title:
date:
updated:
tags:
categories:
keywords:
description:
top_img:
comments:
cover:
toc:
toc_number:
auto_open:
copyright:
mathjax:
katex:
aplayer:
highlight_shrink:
---
写法 | 说明 |
---|---|
title | 【必需】文章标题 |
date | 【必需】文章创建日期 |
updated | 【可选】文章更新日期 |
tags | 【可选】文章标籤 |
categories | 【可选】文章分类 |
keywords | 【可选】文章关键字 |
description | 【可选】文章描述 |
top_img | 【可选】文章顶部图片 |
cover | 【可选】文章缩略图(如果没有设置top_img,文章页顶部将显示缩略图,可设为false/图片地址/留空) |
comments | 【可选】显示文章评论模块(默认 true) |
toc | 【可选】显示文章TOC(默认为设置中toc的enable配置) |
toc_number | 【可选】显示toc_number(默认为设置中toc的number配置) |
auto_open | 【可选】是否自动打开TOC(默认为设置中toc的auto_open配置) |
copyright | 【可选】显示文章版权模块(默认为设置中post_copyright的enable配置) |
mathjax | 【可选】显示mathjax(当设置mathjax的per_page: false时,才需要配置,默认 false) |
katex | 【可选】显示katex(当设置katex的per_page: false时,才需要配置,默认 false) |
aplayer | 【可选】在需要的页面加载aplayer的js和css,请参考文章下面的音乐 配置 |
highlight_shrink | 【可选】配置代码框是否展开(true/false)(默认为设置中highlight_shrink的配置) |
因为主题UI的关係,主页文章节选只支持自动节选和文章页description。
在butterfly里,有四种可供选择
修改主题配置文件:
index_post_content:
method: 3
length: 500 # if you set method to 2 or 3, the length need to config
description在front-matter里添加
title: Hexo-Butterfly主题修改记录(持续更新)
date: 2020-7-20 17:25:00
categories:
- 记录分享
- 网站搭建
description: 这里填写展示在首页的预览文字内容
tags:
- Hexo
hexo new page "pagename"
配置butterfly.yml
code_word_wrap: true
找到HEXO根目录配置文件,將line_number改成false:
highlight:
enable: true
line_number: false
auto_detect: false
tab_replace:
首先安裝插件(hexo-generator-index-pin-top 或者 hexo-generator-indexed)
如果使用hexo-generator-index-pin-top
, 需要先卸载掉hexo-generator-index
,然後在文章的front-matter区域添加top: true屬性來把這篇文章置頂
如果使用hexo-generator-indexed
, 需要先卸载掉hexo-generator-index
,然后在文章的front-matter区域添加sticky: 1
。数值越大,置頂的优先越大。
page页直接在主题配置文件中修改,post页可在front-matter中设置top_img属性,即top_img: 图片地址
在Front-matter中添加cover: 图片地址
,同时在主题配置文件中修改封面配置。
note:
# Note tag style values:
# - simple bs-callout old alert style. Default.
# - modern bs-callout new (v2-v3) alert style.
# - flat flat callout style with background, like on Mozilla or StackOverflow.
# - disabled disable all CSS styles import of note tag.
style: flat
icons: false
border_radius: 3
# Offset lighter of background in % for modern and flat styles (modern: -12 | 12; flat: -18 | 6).
# Offset also applied to label tag variables. This option can work with disabled note tag.
light_bg_offset: 0
用法:
{%note [class] [no-icon] %}
Any content (support inline tags too.io).
{%endnote %}
[class] : default | primary | success | info | warning | danger.
[no-icon] : Disable icon in note.
All parameters are optional.
示例:
{%note default %}
default 提示
{%endnote %}
{%note primary no-icon %}
primary 提示
{%endnote %}
{%note success %}
success 提示
{%endnote %}
{%note info %}
info 提示
{%endnote %}
{%note warning %}
warning 提示
{%endnote %}
{%note danger %}
danger 提示
{%endnote %}
default 提示
primary 提示
success 提示
info 提示
warning 提示
danger 提示
示例:
<div class="gallery-group-main">
{%galleryGroup 'Pixiv' '收藏的一些插画' '/photo/pixiv' https://s.ahzoo.cn/img/pixiv/07.jpg %}
{%galleryGroup 'CG' '永远的7日之都' '/photo/forever7' https://s.ahzoo.cn/img/forever7/05.jpg %}
</div>
Pixiv
收藏的一些插画
CG
永远的7日之都
示例:
{%gallery %}







{%endgallery %}
使用方法:
{%tabs Unique name, [index] %}
<!-- tab [Tab caption] [@icon] -->
Any content (support inline tags too).
<!-- endtab -->
{%endtabs %}
Unique name : Unique name of tabs block tag without comma.
Will be used in #id's as prefix for each tab with their index numbers.
If there are whitespaces in name, for generate #id all whitespaces will replaced by dashes.
Only for current url of post/page must be unique!
[index] : Index number of active tab.
If not specified, first tab (1) will be selected.
If index is -1, no tab will be selected. It's will be something like spoiler.
Optional parameter.
[Tab caption] : Caption of current tab.
If not caption specified, unique name with tab index suffix will be used as caption of tab.
If not caption specified, but specified icon, caption will empty.
Optional parameter.
[@icon] : FontAwesome icon name (full-name, look like 'fas fa-font')
Can be specified with or without space; e.g. 'Tab caption @icon' similar to 'Tab caption@icon'.
Optional parameter.
示例:
{%tabs test1 %}
<!-- tab -->
**This is Tab 1.**
<!-- endtab -->
<!-- tab -->
**This is Tab 2.**
<!-- endtab -->
<!-- tab -->
**This is Tab 3.**
<!-- endtab -->
{%endtabs %}
This is Tab 1.
This is Tab 2.
This is Tab 3.
{%tabs test2, 3 %}
<!-- tab -->
**This is Tab 1.**
<!-- endtab -->
<!-- tab -->
**This is Tab 2.**
<!-- endtab -->
<!-- tab -->
**This is Tab 3.**
<!-- endtab -->
{%endtabs %}
This is Tab 1.
This is Tab 2.
This is Tab 3.
{%tabs test3, -1 %}
<!-- tab -->
**This is Tab 1.**
<!-- endtab -->
<!-- tab -->
**This is Tab 2.**
<!-- endtab -->
<!-- tab -->
**This is Tab 3.**
<!-- endtab -->
{%endtabs %}
This is Tab 1.
This is Tab 2.
This is Tab 3.
自定义 Tab 名 + 只有 icon + icon 和 Tab 名:
{%tabs test4 %}
<!-- tab 第一個Tab -->
**tab名字為第一個Tab**
<!-- endtab -->
<!-- tab @fab fa-apple-pay -->
**只有圖標 沒有Tab名字**
<!-- endtab -->
<!-- tab 炸彈@fas fa-bomb -->
**名字+icon**
<!-- endtab -->
{%endtabs %}
tab名字為第一個Tab
只有圖標 沒有Tab名字
名字+icon
tag-hide 内的标签外挂 content 内都不建议有 h1 - h6 等标题。因为 Toc 会把隐藏内容标题也显示出来,而且当滚动屏幕时,如果隐藏内容没有显示出来,会导致 Toc 的滚动出现异常。
inline 在文本里面添加按钮隐藏内容,只限文字
{%hideInline content,display,bg,color %}
content: 文本内容 display: 按钮显示的文字 (可选) bg: 按钮的背景颜色 (可选) color: 按钮文字的颜色 (可选) ( content 不能包含英文逗号,可用 ‚)
示例:
😓人和人是不能一概而论的 {%hideInline 直接写下了这个示例,我曾经在极度愤怒的情况下,#FF7242,#fff %}
click here{%hideInline true %}
😓人和人是不能一概而论的 我曾经在极度愤怒的情况下 直接写下了这个示例
click hereClick true
block 独立的 block 隐藏内容,可以隐藏很多内容,包括图片,代码块等等
( display 不能包含英文逗号,可用 ‚)
{%hideBlock display,bg,color %}
content
{%endhideBlock %}
content: 文本内容 display: 按钮显示的文字 (可选) bg: 按钮的背景颜色 (可选) color: 按钮文字的颜色 (可选) 示例:
{%hideBlock 查看答案 %}
XXX
{%endhideBlock %}
查看答案
XXX
如果你需要展示的内容太多,可以把它隐藏在收缩框里,需要时再把它展开。
( display 不能包含英文逗号,可用 ‚)
{%hideToggle display,bg,color %}
content
{%endhideToggle %}
示例:
{%hideToggle 显示的标题 %}
隐藏的内容
{%endhideToggle %}
显示的标题
隐藏的内容
{%btn [url],[text],[icon],[color] [style] [layout] [position] [size] %}
[url] : 链接
[text] : 按钮文字
[icon] : [可选] 图标
[color] : [可选] 按钮背景顔色(默认style时)
按钮字体和边框顔色(outline时)
default/blue/pink/red/purple/orange/green
[style] : [可选] 按钮样式 默认实心
outline/留空
[layout] : [可选] 按钮佈局 默认为line
block/留空
[position] : [可选] 按钮位置 前提是设置了layout为block 默认为左边
center/right/留空
[size] : [可选] 按钮大小
larger/留空
示例:
This is my website, click the button {%btn 'http://ahzoo.cn',十玖八柒 %}
This is my website, click the button {%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right %}
This is my website, click the button {%btn 'http://ahzoo.cn',十玖八柒,,outline %}
This is my website, click the button {%btn 'http://ahzoo.cn',十玖八柒 ,far fa-hand-point-right,outline %}
This is my website, click the button {%btn 'http://ahzoo.cn',十玖八柒 ,far fa-hand-point-right,larger %}
This is my website, click the button 十玖八柒 This is my website, click the button 十玖八柒 This is my website, click the button 十玖八柒 This is my website, click the button 十玖八柒 This is my website, click the button 十玖八柒
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,block %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,block center larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,block right outline larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,blue larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,pink larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,red larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,purple larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,orange larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,green larger %}
<div class="btn-center">
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline blue larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline pink larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline red larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline purple larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline orange larger %}
{%btn 'http://ahzoo.cn',十玖八柒,far fa-hand-point-right,outline green larger %}
</div>
十玖八柒 十玖八柒 十玖八柒 十玖八柒 十玖八柒 十玖八柒 十玖八柒
此部分修改主要引用了主题volantis
所以使用下面的功能时需要先下载该主题目录下/scripts/tags/
中需要文件,将其复制至博客主题文件\scripts\tags
路径下,否则会报错
引入代码:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/css/btns.css">
写法:
{%btns 样式参数 %}
{%cell 标题, 链接, 图片或者图标 %}
{%cell 标题, 链接, 图片或者图标 %}
{%endbtns %}
示例:
{%btns circle grid5 %}
{%cell 十玖八柒, https://ahzoo.cn/, https://ahzoo.cn/img/head.jpg %}
{%cell 十玖八柒, https://ahzoo.cn/, https://ahzoo.cn/img/head.jpg %}
{%cell 十玖八柒, https://ahzoo.cn/, https://ahzoo.cn/img/head.jpg %}
{%cell 十玖八柒, https://ahzoo.cn/, https://ahzoo.cn/img/head.jpg %}
{%cell 十玖八柒, https://ahzoo.cn/, https://ahzoo.cn/img/head.jpg %}
{%endbtns %}
{%btns rounded grid5 %}
{%cell 下载源码, /, fa fa-download %}
{%cell 查看文档, /, fa fa-download %}
{%endbtns %}
可以在容器内增加 <b>标题</b>
和 <p>描述文字</p>
圆角参数:
rounded, circle
布局样式:
写法 | 说明 |
---|---|
参数 | 含义 |
wide | 宽一点的按钮 |
fill | 填充布局,自动铺满至少一行,多了会换行。 |
center | 居中,按钮之间是固定间距。 |
around | 居中分散 |
grid2 | 等宽最多2列,屏幕变窄会适当减少列数。 |
grid3 | 等宽最多3列,屏幕变窄会适当减少列数。 |
grid4 | 等宽最多4列,屏幕变窄会适当减少列数。 |
grid5 | 等宽最多5列,屏幕变窄会适当减少列数。 |
引入代码:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/css/btns.css">
写法:
{%folding 参数(可选), 标题 %}
折叠内容
{%endfolding %}
参数位置可以填写颜色和状态,多个参数用空格隔开。 状态填写 open 代表默认打开 颜色:
blue, cyan, green, yellow, red
示例:
{%folding red open, 折叠测试 %}
这里是测试内容
{%endfolding %}
{%folding blue, 图片测试 %}

{%endfolding %}
折叠测试
这里是测试内容
图片测试
引入代码:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/css/timeline.css">
写法:
{%timeline 时间线 %}
{%timenode 2020-08-09 [测试](https://ahzoo.cn/) %}
今天是2020-08-09
{%endtimenode %}
{%timenode 2020-08-08 [测试](https://ahzoo.cn/) %}
今天是2020-08-08
{%endtimenode %}
{%endtimeline %}
时间线
2020-08-09 测试
今天是2020-08-09
2020-08-08 测试
今天是2020-08-08
{% label text color %}
参数 | 解释 |
---|---|
text | 文字 |
color | 【可选】背景颜色,默认为 defaultdefault/blue/pink/red/purple/orange/green |
臣亮言:{% label 先帝 %}创业未半,而{% label 中道崩殂 blue %}。今天下三分,{% label 益州疲敝 pink %},此诚{% label 危急存亡之秋 red %}也!然侍衞之臣,不懈于内;{% label 忠志之士 purple %},忘身于外者,盖追先帝之殊遇,欲报之于陛下也。诚宜开张圣听,以光先帝遗德,恢弘志士之气;不宜妄自菲薄,引喻失义,以塞忠谏之路也。
宫中、府中,俱为一体;陟罚臧否,不宜异同。若有{% label 作奸 orange %}、{% label 犯科 green %},及为忠善者,宜付有司,论其刑赏,以昭陛下平明之治;不宜偏私,使内外异法也。
臣亮言:先帝 创业未半,而中道崩殂 。今天下三分,益州疲敝 ,此诚危急存亡之秋 也!然侍衞之臣,不懈于内;忠志之士 ,忘身于外者,盖追先帝之殊遇,欲报之于陛下也。诚宜开张圣听,以光先帝遗德,恢弘志士之气;不宜妄自菲薄,引喻失义,以塞忠谏之路也。 宫中、府中,俱为一体;陟罚臧否,不宜异同。若有作奸 、犯科 ,及为忠善者,宜付有司,论其刑赏,以昭陛下平明之治;不宜偏私,使内外异法也。
On DOM load | On hover | On parent hover |
---|---|---|
faa-wrench animated | faa-wrench animated-hover | faa-wrench |
faa-ring animated | faa-ring animated-hover | faa-ring |
faa-horizontal animated | faa-horizontal animated-hover | faa-horizontal |
faa-vertical animated | faa-vertical animated-hover | faa-vertical |
faa-flash animated | faa-flash animated-hover | faa-flash |
faa-bounce animated | faa-bounce animated-hover | faa-bounce |
faa-spin animated | faa-spin animated-hover | faa-spin |
faa-float animated | faa-float animated-hover | faa-float |
faa-pulse animated | faa-pulse animated-hover | faa-pulse |
faa-shake animated | faa-shake animated-hover | faa-shake |
faa-tada animated | faa-tada animated-hover | faa-tada |
faa-passing animated | faa-passing animated-hover | faa-passing |
faa-passing-reverse animated | faa-passing-reverse animated-hover | faa-passing-reverse |
faa-burst animated | faa-burst animated-hover | faa-burst |
faa-falling animated | faa-falling animated-hover | faa-falling |
faa-rising animated | faa-rising animated-hover | faa-rising |
如果使用 On parent hover 需要向父级元素添加 class 名 faa-parent animated-hover。其余两个不需要。另外可以通过添加
faa-fast
动画加速,faa-slow
动画减速
引入动态图标时,只需要引入动态图标的开源库:,然后在图标后面添加动态图标属性即可
以menu上的图标为例:
menu:
主页: / || fas fa-home faa-wrench animated
最新版本已弃用此方法
在main.js添加
// 隐藏首页banner图
var full_page = document.getElementsByClassName("full_page");
if (full_page.length != 0) {
full_page[0].style.background = "transparent";
}
//隐藏index顶部图
var notiz = document.getElementsByClassName("not-index-bg");
if (notiz.length != 0) {
notiz[0].style.background = "transparent";
}
最新版本直接在配置文件中修改:
# Disable all banner image
disable_top_img: true
新建一个css并引入:
/*移动端优化:去除归档、标签、最新文章、公告、、只保留网站统计*/
@media screen and (max-width: 768px) {
#aside_content div:not(:last-child) {
display: none;
}
}
引入js:
<script src="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/js/ripples.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/js/ripples1.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/js/ripples2.js"></script>
引入js:
<script src="https://cdn.jsdelivr.net/gh/ooahz/hexo@latest/js/bubble.js"></script>
安装插件
npm i hexo-butterfly-article-double-row --save
# 或者
cnpm i hexo-butterfly-article-double-row --save
在配置文件中添加如下代码:
butterfly_article_double_row:
enable: true
只需要将Front-matter中的tape属性删除即可 以分类界面为例:
只需要将type: categories
删除即可
---
title: 分类
date: 2020-05-20 09:34:30
---
引入CSS:
#aside-content #card-toc .toc-content .toc-link.active {
border-left-color: var(--ahzoo-deep-blue);
background: var(--btn-bg);
border-radius: 7px;
box-shadow: 0 8px 12px -3px rgba(73,177,245,0.2);
}
新建一个css并引入
::-webkit-scrollbar {
width: 5px;
height: 5px;
}
::-webkit-scrollbar-track {
background-color: rgba(73, 177, 245, 0.2);
border-radius: 2em;
}
::-webkit-scrollbar-thumb {
background-color: #49b1f5;
background-image: -webkit-linear-gradient( 45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0.4) 75%, transparent 75%, transparent);
border-radius: 2em;
}
::-webkit-scrollbar-corner {
background-color: transparent;
}
::-moz-selection {
color: #fff;
background-color: #49b1f5;
}
效果见上图
包括右侧的侧边栏按钮,以及右下角按钮
新建一个css并引入
<!--侧边栏按钮-->
#aside-content .card-info #card-info-btn {
border-radius: 15px;
}
.button--animated::before {
border-radius: 15px;
}
<!--右下角按钮侧边栏-->
button{
border-radius: 7px;
}
a#to_comment{
border-radius: 7px;
}
效果见下图
以选中标签为例:
#aside-content .card-tag-cloud a:hover {
color: #eee!important;
margin: 0 auto;
border-radius: 7px;
background: var(--btn-bg);
}
点此展开
以阿里云图标库(Iconfont)为例;
在阿里云图标库找到自己想要引入的图标,点击添加到购物车;
点击购物车,选中添加到项目按钮;
如果没有项目,就新建一个;
添加完成后自动跳转到项目界面;
选择添加方式(Unicode、Font class、Symbol),由于butterfly默认是Font图标,所以我们这里选择Font class(如果要引入Symbol方式的话,就需要自定义代码了),然后点击查看在线链接;
首次会提示需要生成代码(加入新的图标后,会提示更新代码),按照提示生成即可,然后复制生成的代码,在主题配置文件中引入;
复制图标代码(icon-jiaoliu),在需要引入图标的位置填入即可;
以menu菜单为例:
menu:
主页: / || iconfont icon-jiaoliu # 这个就是刚才复制的图标名,前面需要加上iconfont
文章: /categories/ || iconfont icon-003-sakura
友链: /friends/ || fas fa-link
安装插件:
$ npm install --save hexo-blog-encrypt
在需要加密文章的的Front-master中添加password字段或其它扩展字段(不加扩展字段默认提示是英文)
不加拓展字段:
---
title: xxxx
date: 2021-12-02 00:00:00
password: 123456
---
加入拓展字段:
---
title: xxxx
date: 2021-12-02 00:00:00
password: 123456
abstract: 这里有东西被加密了,需要输入密码查看哦。
message: 请在这里输入密码。
wrong_pass_message: 密码输入错误,请重试
wrong_hash_message: 抱歉,这个文章不能被校验,不过您还是能看看解密后的内容。
---
直接在Hexo配置文件中添加代码:
# 文章加密
encrypt:
abstract: 这里有东西被加密了,需要输入密码查看哦。
message: 请在这里输入密码。
tags:
- {name: 标签1, password: 123456}
- {name: 标签2, password: 654321}
# 模板样式
template: <div id="hexo-blog-encrypt" data-wpm="{{hbeWrongPassMessage}}" data-whm="{{hbeWrongHashMessage}}"><div class="hbe-input-container"><input type="password" id="hbePass" placeholder="{{hbeMessage}}" /><label>{{hbeMessage}}</label><div class="bottom-line"></div></div><script id="hbeData" type="hbeData" data-hmacdigest="{{hbeHmacDigest}}">{{hbeEncryptedData}}</script></div>
# 提示信息(不填则默认为英文)
wrong_pass_message: 密码输入错误,请重试
wrong_hash_message: 抱歉, 这个文章不能被校验, 不过您还是能看看解密后的内容.