hexo魔改教程(三)
博客搭建与魔改系列教程导航🚥🚥🚥
- hexo基础教程(一)
- hexo魔改教程(一)
- hexo魔改教程(二)
- hexo魔改教程(三)
本篇是第 21 ~ 30 个魔改,适用Hexo 8.1.2+Butterfly 5.7.2,末节是升级配置清单。
炫彩流光文字
炫彩字
新建 [Blogroot]\source\css\brinks.css,写入:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21.brinks {
display:flex;
z-index:1;
position: relative;
justify-content:center;
font-weight: bold;
background-image: linear-gradient( to left, orangered, orange, gold, lightgreen, cyan, dodgerblue, mediumpurple, hotpink, orangered);
background-size: 100vw 100%;
background-repeat: repeat;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
-webkit-animation: rainbowan 60s linear infinite;
animation: rainbowan 60s linear infinite;
}
@-webkit-keyframes rainbowan {
to { background-position: -2000vw; }
}
@keyframes rainbowan {
to { background-position: -2000vw; }
}background-size 用 100vw、位移用 -2000vw,两者是整数倍关系(20 个周期),循环时颜色能接上,不会跳。
在 [Blogroot]\_config.butterfly.yml 的 inject.head 添加:1
2
3inject:
head:
- <link rel="stylesheet" href="/css/brinks.css"> #炫彩字
在 [Blogroot]\_config.butterfly.yml 使用:1
2footer:
custom_text: <div class="brinks">I wish you to become your own sun, no need to rely on who's light.</div>
全站自定义字体
霞鹜文楷
把字体文件放到 [Blogroot]\source\font\霞鹜文楷.woff2。
在 [Blogroot]\source\css\custom.css 末尾添加:1
2
3
4
5
6
7@font-face {
font-family: 'myfont';
src: url(/font/霞鹜文楷.woff2) format('woff2');
font-weight: normal;
font-style: normal;
font-display: swap;
}
在 [Blogroot]\_config.butterfly.yml 配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15font:
global_font_size: '16px'
code_font_size: '14px'
font_family: myfont, -apple-system, 'Quicksand', 'PingFang SC', 'Microsoft Yahei', sans-serif;
code_font_family: Consolas, myfont, "Microsoft YaHei", Menlo, monospace
blog_title_font:
font_link:
font_family: myfont, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif
beautify:
enable: true
field: post
title_prefix_icon: '\f863'
title_prefix_icon_color: "#F47466"
在 [Blogroot]\_config.butterfly.yml 的 inject.head 添加:1
2
3inject:
head:
- <link rel="preload" as="font" type="font/woff2" href="/font/%E9%9C%9E%E9%B9%9C%E6%96%87%E6%A5%B7.woff2" crossorigin> #正文字体预加载
FontAwesome 图标本地化
图标本地化
把 Font Awesome Free 6.5.1 的三个字体文件放到 [Blogroot]\source\webfonts\:1
2
3source/webfonts/fa-solid-900.woff2
source/webfonts/fa-regular-400.woff2
source/webfonts/fa-brands-400.woff2
把官方 fontawesome.min.css 放到 [Blogroot]\source\css\fontawesome.min.css,其中三个 @font-face 的 src 改成:1
2
3@font-face{font-family:"Font Awesome 6 Free";font-weight:900;src:url(/webfonts/fa-solid-900.woff2) format("woff2")}
@font-face{font-family:"Font Awesome 6 Free";font-weight:400;src:url(/webfonts/fa-regular-400.woff2) format("woff2")}
@font-face{font-family:"Font Awesome 6 Brands";font-weight:400;src:url(/webfonts/fa-brands-400.woff2) format("woff2")}
在 [Blogroot]\_config.butterfly.yml 配置:1
2
3CDN:
option:
fontawesome: /css/fontawesome.min.css
在 [Blogroot]\_config.butterfly.yml 的 inject.head 添加:1
2
3
4inject:
head:
- <link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
- <link rel="dns-prefetch" href="https://cdn.jsdelivr.net">
菜单图标用 FA6 正式类名:1
2menu:
隐私政策||fas fa-shield-halved: /privacy/ || fas fa-shield-halved
一图流背景与遮罩
一图流
把背景图放到 [Blogroot]\source\img\bg.webp。
在 [Blogroot]\_config.butterfly.yml 配置:1
2
3
4
5
6
7background: /img/bg.webp
index_img:
default_top_img:
footer_img: false
mask:
header: true
footer: true
在 [Blogroot]\source\css\custom.css 末尾添加:1
2
3
4[data-theme="light"] #footer::before { background: rgba(255,255,255,.5); }
[data-theme="dark"] #footer::before { background: rgba(0,0,0,.5); }
[data-theme="light"] #page-header::before { background: rgba(255,255,255,.3); }
[data-theme="dark"] #page-header::before { background: rgba(0,0,0,.3); }
在 [Blogroot]\_config.butterfly.yml 的 inject.head 添加:1
2
3inject:
head:
- <link rel="preload" as="image" href="/img/bg.webp" fetchpriority="high"> #首屏背景预加载
页脚计时器与框架徽标
页脚徽标
把插件资源放到对应路径:1
2
3
4
5source/js/runtime.js
source/css/runtime.css
source/css/swiper.min.css
source/js/swiper.min.js
source/js/swiperbdage_init.min.js
在 [Blogroot]\themes\butterfly\layout\includes\layout.pug 的 footer#footer 内补一层容器:1
2
3footer#footer(style=footer_bg)
#footer-wrap
!=partial('includes/footer', {}, {cache: true})
在 [Blogroot]\source\css\custom.css 末尾添加:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#footer #footer-wrap > * { position: relative; color: var(--light-grey); }
#footer-wrap .footer-other,
#footer-wrap .beian-row,
#footer-wrap #workboard,
#footer-wrap #ghbdages { text-align: center; }
#footer #footer-wrap {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
column-gap: 5px;
}
#footer-wrap > .footer-other { flex: 0 0 100%; order: 0; }
#footer-wrap > #workboard { flex: 0 0 100%; order: 1; }
#footer-wrap > .beian-row,
#footer-wrap > #ghbdages { order: 2; flex: 0 0 auto; max-width: 100%; margin-top: 8px; }
#footer-wrap > #ghbdages {
display: inline-flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
margin: 8px 0 0;
line-height: 1;
}
在 [Blogroot]\_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
28footer_beautify:
enable:
timer: true
bdage: true
priority: 5
enable_page: all
layout:
type: id
name: footer-wrap
index: 0
runtime_js: /js/runtime.js
runtime_css: /css/runtime.css
bdageitem:
- link: https://hexo.io/
shields: https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo
message: 博客框架为Hexo_v8.1.2
- link: https://butterfly.js.org/
shields: https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender
message: 主题版本Butterfly_v5.7.2
- link: https://<你的服务商>/
shields: https://img.shields.io/badge/Host-<你的服务商>-0052D9?style=flat
message: 站点托管信息
- link: http://creativecommons.org/licenses/by-nc-sa/4.0/
shields: https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat
message: 本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可
swiper_css: /css/swiper.min.css
swiper_js: /js/swiper.min.js
swiperbdage_init_js: /js/swiperbdage_init.min.js
小冰分类磁贴
分类磁贴
在 [Blogroot]\_config.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
30magnet:
enable: true
priority: 1
enable_page: /
type: categories
devide: 2
display:
- name: 校园生活
display_name: 校园生活
icon: 📚
- name: 编程语言
display_name: 乱写代码
icon: 🎮
- name: music
display_name: 音乐
icon: 🎧
- name: AI
display_name: AI 探索
icon: 👩💻
color_setting:
text_color: black
text_hover_color: white
background_color: "#f2f2f2"
background_hover_color: "#b30070"
layout:
type: id
name: recent-posts
index: 0
temple_html: '<div class="recent-post-item" style="width:100%;height: auto"><div id="catalog_magnet">${temple_html_item}</div></div>'
plus_style: ""
依赖 [Blogroot]\package.json 里的 hexo-magnet。
历史上的今天
历史上的今天
在 [Blogroot]\_config.yml 配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18history_calendar:
priority: 4
enable: true
enable_page: all
layout:
type: class
name: sticky_layout
index: 0
temple_html: '<div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div></div>'
electric_clock:
priority: 5
enable: false
enable_page: all
layout:
type: class
name: sticky_layout
index: 0
依赖 [Blogroot]\package.json 里的 hexo-history-calendar、hexo-electric-clock。
首页置顶轮播与文章双栏
轮播与双栏
在 [Blogroot]\_config.yml 配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16swiper:
enable: true
priority: 2
enable_page: /
layout:
type: id
name: recent-posts
index: 0
temple_html: '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container">${temple_html_item}</div></div>'
plus_style: ""
butterfly_article_double_row:
enable: true
stylus:
compress: true
在文章 front matter 里写 top: 1。
在 [Blogroot]\source\css\custom.css 末尾添加 5.x 双排适配: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@media screen and (min-width: 769px) {
#recent-posts > .recent-post-items {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: flex-start;
width: 100%;
}
#recent-posts > .recent-post-items > .recent-post-item {
display: flex;
flex-direction: column;
width: 49%;
height: auto ;
margin-top: 1rem;
}
#recent-posts > .recent-post-items > .recent-post-item > .post_cover {
order: 0 ;
width: 100% ;
height: 200px;
flex: 0 0 200px;
}
#recent-posts > .recent-post-items > .recent-post-item > .recent-post-info {
width: 100% ;
padding: 0 40px;
margin-top: 1em;
}
#recent-posts > .recent-post-items > .recent-post-item > .recent-post-info > .content {
display: none;
}
#recent-posts > .recent-post-items > .recent-post-item > .recent-post-info > .article-title {
-webkit-line-clamp: 1;
margin-top: .3rem;
margin-bottom: .3rem;
font-size: 1.2em;
line-height: 1.4;
color: var(--text-highlight-color);
}
#recent-posts > .recent-post-items > .recent-post-item > .recent-post-info > .article-meta-wrap {
margin-bottom: 1rem;
}
#recent-posts > .recent-post-items > .pagination,
#recent-posts > .recent-post-items > #pagination,
#recent-posts > .recent-post-items > nav {
width: 100%;
flex: 0 0 100%;
}
}
html.low-perf #recent-posts > .recent-post-items > .recent-post-item {
content-visibility: auto;
contain-intrinsic-size: auto 320px;
}
页脚备案三连(ICP / 公安 / 萌ICP)
备案三连
在 [Blogroot]\_config.butterfly.yml 新增顶层 beian 段:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18beian:
icp:
number: ICP备<你的备案号>号-1
label: ICP备
link: https://beian.miit.gov.cn/
pending: true
police:
number: 公网安备<你的备案号>号
label: 公网安备
code: ''
icon: /img/beian.png
link: 'https://beian.mps.gov.cn/#/query/webSearch'
pending: true
moe:
number: 萌ICP备<你的编号>号
label: 萌ICP备
link: https://icp.gov.moe/
pending: false
在 [Blogroot]\themes\butterfly\layout\includes\footer.pug 末尾添加: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//- 备案信息三连
if theme.beian
.beian-row
- const icp = theme.beian.icp
if icp
if icp.pending
span.beian-item.beian-item--pending(title='工信部 ICP 备案办理中,下号后显示备案号')
span.beian-item__key= icp.label || 'ICP备'
span.beian-item__val 办理中
else
a.beian-item.beian-item--icp(href=icp.link target='_blank' rel='noopener noreferrer' title=icp.number)
span.beian-item__key= icp.label || 'ICP备'
span.beian-item__val= icp.number.replace(icp.label || '', '')
- const police = theme.beian.police
if police
if police.pending
span.beian-item.beian-item--pending(title='公安联网备案办理中,下号后显示备案号')
span.beian-item__key= police.label || '公网安备'
span.beian-item__val 办理中
else
a.beian-item.beian-item--icp(href=`${police.link}?code=${police.code}` target='_blank' rel='noopener noreferrer' title=police.number)
if police.icon
img.beian-police-icon(src=url_for(police.icon) alt='公安备案')
span.beian-item__key= police.label || '公网安备'
span.beian-item__val= police.number.replace(police.label || '', '')
- const moe = theme.beian.moe
if moe
a.beian-item.beian-item--moe(href=moe.link target='_blank' rel='noopener noreferrer' title='萌国 ICP 备案(非官方趣味标识,非工信部备案)')
span.beian-item__key= moe.label || '萌ICP备'
span.beian-item__val= moe.number.replace(moe.label || '', '')
在 [Blogroot]\source\css\custom.css 末尾添加: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#footer-wrap .beian-row {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 5px;
margin-top: 8px;
}
.beian-item {
display: inline-flex;
align-items: stretch;
overflow: hidden;
height: 20px;
border-radius: 3px;
font-size: 11px;
line-height: 20px;
white-space: nowrap;
text-decoration: none ;
transition: transform .25s ease, box-shadow .25s ease;
}
.beian-item__key,
.beian-item__val { display: inline-flex; align-items: center; color: #fff; }
.beian-item__key { padding: 0 5px; background: #5a6b7b; }
.beian-item__val { padding: 0 6px; background: #5ea6e5; }
.beian-item--pending { cursor: default; }
.beian-item--pending .beian-item__key { background: #6b7684; }
.beian-item--pending .beian-item__val { background: #9aa7b4; }
.beian-item--moe .beian-item__key { background: #7a3a63; }
.beian-item--moe .beian-item__val { background: #f838b2; }
a.beian-item:hover { transform: translateY(-2px); box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.beian-police-icon { width: 12px; height: 12px; object-fit: contain; margin-right: 4px; }
[data-theme="dark"] .beian-item--pending .beian-item__val { background: #6f7b88; }
@media screen and (max-width: 768px) {
#footer-wrap .beian-row { gap: 4px; }
.beian-item { font-size: 10px; height: 18px; line-height: 18px; }
}pending: true 显示「办理中」不生成链接;下号后填 number / code 并把 pending 改成 false。
Hexo 8 / Butterfly 5.7.2 配置清单
大版本升级迁移
在 [Blogroot]\package.json 添加:1
"engines": { "node": ">=20.19.0" }
执行:1
2npm install hexo@8.1.2 --save-exact
hexo clean && hexo g[Blogroot]\_config.butterfly.yml 配置键映射:
| 4.x | 5.x |
| —- | —- |
| local_search.enable: true | search.use: local_search |
| fancybox: true / medium_zoom | lightbox: fancybox |
| mathjax.enable: true | math.use: mathjax |
| sharejs.enable: true | share.use: sharejs |
| highlight_theme 等 6 个键 | code_blocks.theme / macStyle / copy / language / shrink / height_limit / word_wrap / fullpage |
| footer_bg | footer_img |
| footer.copyright: false | footer.copyright: { enable: false, version: false } |
| footer_beautify 徽标文案 | Hexo_v8.1.2 / Butterfly_v5.7.2 |
连字符键改成下划线键:
| 4.x | 5.x |
| —- | —- |
| font.global-font-size | font.global_font_size |
| font.code-font-size | font.code_font_size |
| font.font-family | font.font_family |
| font.code-font-family | font.code_font_family |
| beautify.title-prefix-icon | beautify.title_prefix_icon |
| beautify.title-prefix-icon-color | beautify.title_prefix_icon_color |
| hr_icon.icon-top | hr_icon.icon_top |background 只填纯路径:1
background: /img/bg.webp
[Blogroot]\themes\butterfly\layout\includes\layout.pug 补 #footer-wrap:1
2
3footer#footer(style=footer_bg)
#footer-wrap
!=partial('includes/footer', {}, {cache: true})[Blogroot]\themes\butterfly\layout\includes\layout.pug 删掉 4.x 手加的 third-party/search/index 那行。
模板判断改成:1
if globalPageType === 'post'
1
2if top_img === false && page.type != 'music' && page.title
h1.page-title= page.title[Blogroot]\themes\butterfly\source\js\sun_moon.js 用 btf.activateDarkMode() / btf.activateLightMode() / btf.saveToLocal.set('theme', mode, 2),代码见第二章第 11 项。[Blogroot]\source\css\custom.css 追加 5.x 双排适配,代码见本章第 28 项。
保持不动的挂载点:#recent-posts、.sticky_layout、.recent-post-item。
生成后检查:1
hexo clean && hexo g
在 public/index.html 中确认存在:footer-wrap、beian-row、rightMenu、main-hero-waves-area、loading-image-dot、recent-post-items。
