博客视觉魔改
首先在[Blogroot]/source/
文件夹下新建两个文件夹css
和js
。
在两个文件夹下分别创建一个custom.css
和custom.js
文件。
它们分别存放自定义的CSS和JavaScript代码。
然后在主题配置文件[Blogroot]/_config.butterfly.yml
中找到插入外部代码部分,引入custom.css
和custom.js
:
1 2 3 4 5 6 7 8 9
| inject: head: - <link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'">
bottom: - <script src="/js/custom.js"></script> - <script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script>
|
网站背景一图流
为了使得整个网站从上到下都是一张背景图,我们需要在[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
| #footer { background: transparent !important; } #page-header { background: transparent !important; } #footer::before { background: transparent !important; } #page-header::before { background: transparent !important; } [data-theme="dark"] #footer::before { background: transparent !important; } [data-theme="dark"] #page-header::before { background: transparent !important; }
|
如果之前设置过网站主页的顶图及页脚背景图的,取消设置,避免冗余加载:
1 2 3 4 5
| index_img:
footer_bg: false
|
最后,为网站设置一个背景:
1 2 3 4
|
background: url(https://tuchuang.voooe.cn/images/2023/11/28/top1.webp)
|
导航栏魔改
导航栏结构修改:
首先,找到[Blogroot]/themes/butterfly/layout/includes/header/nav.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
| nav#nav //- 导航栏左侧显示LOGO及站名 span#blog-info a(href=url_for('/') title=config.title) if theme.nav.logo img.site-icon(src=url_for(theme.nav.logo)) if theme.nav.display_title span.site-name=config.title //- 导航栏中间显示菜单及文章标题 #menus !=partial('includes/header/menu_item', {}, {cache: true}) center(id="name-container") //- 假设文章标题是动态设置的,这里仅作为占位符 a(id="page-name" href="javascript:scrollToTop()") 文章标题 //- 导航栏右侧显示搜索按钮 #nav-right if (theme.algolia_search.enable || theme.local_search.enable || theme.docsearch.enable) #search-button a.site-page.social-icon.search(href="javascript:void(0);") i.fas.fa-search.fa-fw //- span=' '+_p('search.title') #toggle-menu a.site-page(href="javascript:void(0);") i.fas.fa-bars.fa-fw
|
导航栏相关样式修改
在[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 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#nav { display: grid; grid-template-columns: 1fr 2fr 1fr; align-items: center; padding: 0 10px; }
#blog-info { text-align: left; }
.site-icon { margin-top: -5px } #menus { display: flex; justify-content: center; align-items: center; }
#nav-right { display: flex; justify-content: flex-end; }
#nav .menus_items .menus_item:hover .menus_item_child { display: flex !important; }
.menus_items .menus_item:nth-child(2) .menus_item_child { left: -125px; }
#nav *::after{ background-color: transparent!important; }
.site-page { font-size: 0.9em; font-weight: bold; }
#page-name::before { font-size: 18px; position: absolute; width: 100%; height: 100%; border-radius: 8px; color: white !important; top: 0; left: 0; content: "回到顶部"; background-color: var(--theme-color); transition: all 0.3s; -webkit-transition: all 0.3s; -moz-transition: all 0.3s; -ms-transition: all 0.3s; -o-transition: all 0.3s; opacity: 0; box-shadow: 0 0 3px var(--theme-color); line-height: 45px; } #page-name:hover:before { opacity: 1; } #name-container { transition: all 0.3s; -webkit-transition: all 0.3s; -moz-transition: all 0.3s; -ms-transition: all 0.3s; -o-transition: all 0.3s; } #name-container:hover { scale: 1.03; } #page-name { font-weight: bold; position: relative; padding: 10px 30px; } #nav{ padding: 0 20px; }
@media (max-width: 767px) { #page-name { display: none; } }
|
导航栏显示逻辑相关:
然后在[Blogroot]/source/js/custom.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
| document.addEventListener("pjax:complete", tonav); document.addEventListener("DOMContentLoaded", tonav);
function tonav() { document .getElementById("name-container") .setAttribute("style", "display:none"); var position = $(window).scrollTop(); $(window).scroll(function () { var scroll = $(window).scrollTop(); if (scroll > position) { document.getElementById("name-container").setAttribute("style", ""); document .getElementsByClassName("menus_items")[1] .setAttribute("style", "display:none!important"); } else { document .getElementsByClassName("menus_items")[1] .setAttribute("style", ""); document .getElementById("name-container") .setAttribute("style", "display:none"); } position = scroll; }); document.getElementById("page-name").innerText = document.title.split(" | 猫野")[0]; }
function scrollToTop() { document.getElementsByClassName("menus_items")[1].setAttribute("style", ""); document .getElementById("name-container") .setAttribute("style", "display:none"); btf.scrollToDest(0, 500); }
|
最后,在主题配置文件[Blogroot]/_config.butterfly.yml
中的插入外部代码部分引入[Blogroot]/source/js/custom.js
:
1 2 3 4 5
| bottom:
- <script src="/js/custom.js"></script>
- <script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script>
|
首页魔改
文章双栏展示
原本的首页文章是单栏展示的,如果需要双栏显示,需要安装额外的插件:
1
| npm install hexo-maoye-double-article --save
|
随后在主题配置文件[Blogroot]/_config.burterfly.yml
的特定元素板块最后添加如下内容:
1 2 3
| article_double_row: enable: true
|
在[Blogroot]/source/css/custom.css
中添加如下内容:
1 2 3 4 5 6 7 8 9 10
|
#pagination { width: 100%; margin: auto; } .page-number.current { background-color: var(--theme-color)!important; }
|
元素出场动画
我们可以为首页上文章卡片、侧边栏等添加动画。
在站点配置文件[Blogroot]/_config.yml
中添加如下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| wowjs: enable: true priority: 10 mobile: false animateitem: - class: recent-post-item style: animate__bounceInLeft - class: card-widget style: animate__bounceInRight animate_css: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css wow_js: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js wow_init_js: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js
|
霓虹灯效果
我们可以为网站标题、副标题、文章标题、文章信息等添加霓虹灯效果。
在[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 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
[data-theme="light"] .site-name, [data-theme="light"] #site-title, [data-theme="light"] #site-subtitle, [data-theme="light"] #page-name, [data-theme="light"] #post-info { animation: none; }
[data-theme="dark"] .site-name, [data-theme="dark"] #site-title { animation: light_15px 10s linear infinite; } [data-theme="dark"] #site-subtitle { animation: light_10px 10s linear infinite; } [data-theme="dark"] #page-name { animation: light_10px 10s linear infinite; } [data-theme="dark"] #post-info { animation: light_5px 10s linear infinite; }
@keyframes light_15px { 0% { text-shadow: #5636ed 0 0 15px; } 12.5% { text-shadow: #11ee5e 0 0 15px; } 25% { text-shadow: #f14747 0 0 15px; } 37.5% { text-shadow: #f1a247 0 0 15px; } 50% { text-shadow: #f1ee47 0 0 15px; } 50% { text-shadow: #b347f1 0 0 15px; } 62.5% { text-shadow: #002afa 0 0 15px; } 75% { text-shadow: #ed709b 0 0 15px; } 87.5% { text-shadow: #39c5bb 0 0 15px; } 100% { text-shadow: #5636ed 0 0 15px; } }
@keyframes light_10px { 0% { text-shadow: #5636ed 0 0 10px; } 12.5% { text-shadow: #11ee5e 0 0 10px; } 25% { text-shadow: #f14747 0 0 10px; } 37.5% { text-shadow: #f1a247 0 0 10px; } 50% { text-shadow: #f1ee47 0 0 10px; } 50% { text-shadow: #b347f1 0 0 10px; } 62.5% { text-shadow: #002afa 0 0 10px; } 75% { text-shadow: #ed709b 0 0 10px; } 87.5% { text-shadow: #39c5bb 0 0 10px; } 100% { text-shadow: #5636ed 0 0 10px; } }
@keyframes light_5px { 0% { text-shadow: #5636ed 0 0 5px; } 12.5% { text-shadow: #11ee5e 0 0 5px; } 25% { text-shadow: #f14747 0 0 5px; } 37.5% { text-shadow: #f1a247 0 0 15px; } 50% { text-shadow: #f1ee47 0 0 5px; } 50% { text-shadow: #b347f1 0 0 5px; } 62.5% { text-shadow: #002afa 0 0 5px; } 75% { text-shadow: #ed709b 0 0 5px; } 87.5% { text-shadow: #39c5bb 0 0 5px; } 100% { text-shadow: #5636ed 0 0 5px; } }
|
夜间星空背景
我们可以为网站背景添加夜间星空背景。
在[Blogroot]/source/css/custom.css
中添加如下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #universe{ display: block; position: fixed; margin: 0; padding: 0; border: 0; outline: 0; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; z-index: -1; }
|
在[Blogroot]/source/js/custom.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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| function dark() { window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; var n, e, i, h, t = 0.05, s = document.getElementById("universe"), o = !0, a = "180,184,240", r = "226,225,142", d = "226,225,224", c = []; function f() { (n = window.innerWidth), (e = window.innerHeight), (i = 0.216 * n), s.setAttribute("width", n), s.setAttribute("height", e); } function u() { h.clearRect(0, 0, n, e); for (var t = c.length, i = 0; i < t; i++) { var s = c[i]; s.move(), s.fadeIn(), s.fadeOut(), s.draw(); } } function y() { (this.reset = function () { (this.giant = m(3)), (this.comet = !this.giant && !o && m(10)), (this.x = l(0, n - 10)), (this.y = l(0, e)), (this.r = l(1.1, 2.6)), (this.dx = l(t, 6 * t) + (this.comet + 1 - 1) * t * l(50, 120) + 2 * t), (this.dy = -l(t, 6 * t) - (this.comet + 1 - 1) * t * l(50, 120)), (this.fadingOut = null), (this.fadingIn = !0), (this.opacity = 0), (this.opacityTresh = l(0.2, 1 - 0.4 * (this.comet + 1 - 1))), (this.do = l(5e-4, 0.002) + 0.001 * (this.comet + 1 - 1)); }), (this.fadeIn = function () { this.fadingIn && ((this.fadingIn = !(this.opacity > this.opacityTresh)), (this.opacity += this.do)); }), (this.fadeOut = function () { this.fadingOut && ((this.fadingOut = !(this.opacity < 0)), (this.opacity -= this.do / 2), (this.x > n || this.y < 0) && ((this.fadingOut = !1), this.reset())); }), (this.draw = function () { if ((h.beginPath(), this.giant)) (h.fillStyle = "rgba(" + a + "," + this.opacity + ")"), h.arc(this.x, this.y, 2, 0, 2 * Math.PI, !1); else if (this.comet) { (h.fillStyle = "rgba(" + d + "," + this.opacity + ")"), h.arc(this.x, this.y, 1.5, 0, 2 * Math.PI, !1); for (var t = 0; t < 30; t++) (h.fillStyle = "rgba(" + d + "," + (this.opacity - (this.opacity / 20) * t) + ")"), h.rect( this.x - (this.dx / 4) * t, this.y - (this.dy / 4) * t - 2, 2, 2 ), h.fill(); } else (h.fillStyle = "rgba(" + r + "," + this.opacity + ")"), h.rect(this.x, this.y, this.r, this.r); h.closePath(), h.fill(); }), (this.move = function () { (this.x += this.dx), (this.y += this.dy), !1 === this.fadingOut && this.reset(), (this.x > n - n / 4 || this.y < 0) && (this.fadingOut = !0); }), setTimeout(function () { o = !1; }, 50); } function m(t) { return Math.floor(1e3 * Math.random()) + 1 < 10 * t; } function l(t, i) { return Math.random() * (i - t) + t; } f(), window.addEventListener("resize", f, !1), (function () { h = s.getContext("2d"); for (var t = 0; t < i; t++) (c[t] = new y()), c[t].reset(); u(); })(), (function t() { document.getElementsByTagName("html")[0].getAttribute("data-theme") == "dark" && u(), window.requestAnimationFrame(t); })(); } dark();
|
最后在主题配置文件中引入一个画板,注意先后顺序:
1 2 3 4 5 6 7 8 9 10 11 12 13
| inject:
head: - <link rel="stylesheet" href="/css/custom.css" media="defer"
bottom:
+ - <canvas id="universe"></canvas>
- <script src="/js/custom.js"></script>
- <script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script> # jQuery依赖
|
头像呼吸灯
在[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
| [data-theme="light"] .avatar-img { animation: huxi_light 4s ease-in-out infinite; } [data-theme="dark"] .avatar-img { animation: huxi_dark 4s ease-in-out infinite; } @keyframes huxi_light { 0% { box-shadow: 0px 0px 1px 1px #e9f5fa; } 50% { box-shadow: 0px 0px 5px 5px #e9f5fa; } 100% { box-shadow: 0px 0px 1px 1px #e9f5fa; } } @keyframes huxi_dark { 0% { box-shadow: 0px 0px 1px 1px #39c5bb; } 50% { box-shadow: 0px 0px 5px 5px #39c5bb; } 100% { box-shadow: 0px 0px 1px 1px #39c5bb; } }
|
页面样式魔改
首先在[BlogRoot]/source/css/custom.css
中的头部添加如下内容:
1 2 3 4 5 6 7
| :root { --trans-light: rgba(255, 255, 255, 0.6); --trans-dark: rgba(25, 25, 25, 0.3); --border-style: 1px solid rgb(169, 169, 169); --backdrop-filter: blur(5px) saturate(150%); }
|
随后在[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 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 71 72 73 74 75 76 77 78
|
#aside-content > .card-widget.card-info { background: var(--trans-light); backdrop-filter: var(--backdrop-filter); border-radius: 25px; border: var(--border-style); }
[data-theme="dark"] #aside-content > .card-widget.card-info { background: var(--trans-dark); }
#recent-posts > .recent-post-item { background: var(--trans-light); backdrop-filter: var(--backdrop-filter); border-radius: 25px; border: var(--border-style); }
#aside-content .card-widget { background: var(--trans-light); backdrop-filter: var(--backdrop-filter); border-radius: 18px; border: var(--border-style); }
div#post, div#page, div#archive { background: var(--trans-light); backdrop-filter: var(--backdrop-filter); border: var(--border-style); border-radius: 20px; }
#page-header.nav-fixed #nav { background: var(--trans-light); backdrop-filter: var(--backdrop-filter); }
[data-theme="dark"] #page-header.nav-fixed #nav { background: rgba(0, 0, 0, 0.3) !important; }
[data-theme="dark"] #recent-posts > .recent-post-item, [data-theme="dark"] #aside-content .card-widget, [data-theme="dark"] div#post, [data-theme="dark"] div#archive, [data-theme="dark"] div#page { background: var(--trans-dark); }
.read-mode #aside-content .card-widget { background: rgba(158, 204, 171, 0.5) !important; } .read-mode div#post { background: rgba(158, 204, 171, 0.5) !important; }
[data-theme="dark"] .read-mode #aside-content .card-widget { background: rgba(25, 25, 25, 0.9) !important; color: #ffffff; } [data-theme="dark"] .read-mode div#post { background: rgba(25, 25, 25, 0.9) !important; color: #ffffff; }
|
图标魔改
引入自定义图标
参考教程:Iconfont Inject | Akilarの糖果屋
图标准备
首先,去iconfont-阿里巴巴矢量图标库注册登录,搜索自己心仪的图标,然后选择添加入库,加到购物车,在购物车中可以将加购的图标都添加到项目中,可以新建一个blog项目用于存放图标。
随后,到我的项目中打开项目设置,注意勾选彩色,这样可以多彩图标,但是开了这个后,一个项目只能存放40个彩色图标。
图标引入
线上引入方案简单便捷,本地引入方案麻烦些但稳定,看个人选择。我图简单,用的symbol的在线链接引入(iconfont说symbol是今后大流):
在主题配置文件中`[Blogroot]/_config.butterfly.yml中添加Symbol的在线连接:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| inject:
head:
# - <link rel="stylesheet" href="/xxx.css">
- <link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'">
bottom:
# - <script src="xxxx"></script>
- <canvas id="universe"></canvas>
- <script src="/js/custom.js"></script>
- <script src="https://cdn.staticfile.org/jquery/3.6.3/jquery.min.js"></script> # jQuery依赖
+ - <script async src="//at.alicdn.com/t/c/font_4350076_9d1p8d0va1.js"></script> # symbol方式引入iconfont
|
随后在[BlogRoot]/source/css/custom.css
中添加如下内容,作为引入图标的通用样式:
1 2 3 4 5 6 7 8
| svg.icon { width: 1.5em; height: 1.5em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; }
|
图标替换
找到[Blogroot]/themes/butterfly/layout/includes/header/menu_item.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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| if theme.menu .menus_items each value, label in theme.menu if typeof value !== 'object' .menus_item - const valueArray = value.split('||') a.site-page.faa-parent.animated-hover(href=url_for(trim(value.split('||')[0]))) if valueArray[1] i.fa-fw(class=trim(valueArray[1])) - var icon_value = trim(value.split('||')[1]) - var anima_value = value.split('||')[2] ? trim(value.split('||')[2]) : 'faa-tada' if icon_value.substring(0,2)=="fa" i.fa-fw(class=icon_value + ' ' + anima_value) else if icon_value.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_value,style="height:30px;width:30px;fill:currentColor;position:relative;top:6px") use(xlink:href=`#`+ icon_value) span=' '+label else .menus_item - const labelArray = label.split('||') - const hideClass = labelArray[3] && trim(labelArray[3]) === 'hide' ? 'hide' : '' a.site-page.group.faa-parent.animated-hover(class=`${hideClass}` href='javascript:void(0);') if labelArray[1] - var icon_label = trim(label.split('||')[1]) - var anima_label = label.split('||')[2] ? trim(label.split('||')[2]) : 'faa-tada' if icon_label.substring(0,2)=="fa" i.fa-fw(class=icon_label + ' ' + anima_label) else if icon_label.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_label,style="height:30px;width:30px;fill:currentColor;position:relative;top:6px") use(xlink:href=`#`+ icon_label) span=' '+ trim(labelArray[0]) i.fas.fa-chevron-down ul.menus_item_child each val,lab in value - const valArray = val.split('||') li a.site-page.child.faa-parent.animated-hover(href=url_for(trim(val.split('||')[0]))) if valArray[1] - var icon_val = trim(val.split('||')[1]) - var anima_val = val.split('||')[2] ? trim(val.split('||')[2]) : 'faa-tada' if icon_val.substring(0,2)=="fa" i.fa-fw(class=icon_val + ' ' + anima_val) else if icon_val.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_val,style="height:30px;width:30px;fill:currentColor;position:relative;top:6px") use(xlink:href=`#`+ icon_val) span=' '+ lab
|
找到[Blogroot]/themes/butterfly/layout/includes/header/nav.pug
,替换对应的search-button
部分:
1 2 3 4 5 6 7
| #nav-right if (theme.algolia_search.enable || theme.local_search.enable || theme.docsearch.enable) #search-button a.search.faa-parent.animated-hover(title="检索站内任何你想要的信息") svg.faa-tada.icon(style="height:30px;width:30px;fill:currentColor;position:relative;top:6px", aria-hidden="true") use(xlink:href='#icon-sousuo') //- span=' '+_p('search.title')
|
找到[Blogroot]/themes/butterfly/layout/includes/header/social.pug
,替换其内容:
1 2 3 4 5 6 7 8 9 10
| each value, title in theme.social a.social-icon.faa-parent.animated-hover(href=url_for(trim(value.split('||')[0])) target="_blank" title=title === undefined ? '' : trim(title)) if value.split('||')[1] - var icon_value = trim(value.split('||')[1]) - var anima_value = value.split('||')[2] ? trim(value.split('||')[2]) : 'faa-tada' if icon_value.substring(0,2)=="fa" i.fa-fw(class=icon_value + ' ' + anima_value) else if icon_value.substring(0,4)=="icon" svg.icon(aria-hidden="true" class=anima_value) use(xlink:href=`#`+ icon_value)
|
如此就可以在主题配置文件中设置想要的iconfont图标了:
1 2 3 4 5
| social:
github: https://github.com/fumeng6 || icon-github || faa-tada
邮箱: mailto:6mengfu@gmail.com || icon-youxiang || faa-tada
|
因为都是一样改法,所以只用一个公告卡片举例。
找到[BlogRoot]/themes/butterfly/layout/includes/widget/card_announcement.pug
,替换其内容:
1 2 3 4 5 6 7 8
| if theme.aside.card_announcement.enable .card-widget.card-announcement .item-headline a.faa-parent.animated-hover svg.faa-tada.icon(style="height:25px;width:25px;fill:currentColor;position:relative;top:5px" aria-hidden="true") use(xlink:href='#icon-wangyuanjing') span= _p('aside.card_announcement') .announcement_content!= theme.aside.card_announcement.content
|
都改了公告卡片的图标,那自然“公告”二字也能改。
找到[BlogRoot]/themes/butterfly/languages/zh-CN.yml
(你设置的网站语言是哪个就找哪个),修改对应的文字:
1 2 3 4 5 6
| aside: articles: 归档 tags: 标签 categories: 分类 - card_announcement: 公告 + card_announcement: 通知栏
|
如果想修改其他的侧边栏卡片,基本也是同理。
版权卡片及打赏按钮魔改
在文章页末尾会显示版权信息卡片和打赏按钮,可以根据自己的需求进行修改。
在[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 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 71 72 73 74 75 76 77 78 79
| .post-copyright { border: 1px solid #ddd; padding: 15px; border-radius: 30px; box-shadow: 0 2px 5px rgba(0,0,0,1); margin-top: 20px; }
.post-copyright i { color: #3498db; } .post-copyright-meta, .post-copyright-info { font-size: 16px; line-height: 1.5; }
.post-copyright a { color: #3498db; text-decoration: none; } .post-copyright a:hover { text-decoration: underline; }
.post-copyright { display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 768px) { .post-copyright { padding: 10px; font-size: 14px; } }
.reward-button { padding: 10px 20px; border-radius: 10px; margin: 10px 0; box-shadow: 0 2px 5px rgba(0,0,0,1); transition: background-color 0.3s; }
.reward-main { text-align: center; }
.reward-all { list-style: none; padding: 0; display: inline-block; }
.reward-item { display: inline-block; margin: 0 10px; }
.post-qr-code-img { width: 200px; height: auto; border: 1px solid #ddd; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.post-qr-code-desc { color: #666; font-size: 14px; margin-top: 5px; }
|
网站背景魔改
原本的设定中,背景图片是通过background
属性设置的,但这样只能设置一张图片,如果想设置多张图片,可以找到[Blogroot]/themes/butterfly/layout/includes/layout.pug
,修改其内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| + - var DefaultBg = page.defaultbg ? page.defaultbg : theme.background.default + - var DDMBg = theme.background.darkmode ? theme.background.darkmode : DefaultBg + - var DarkmodeBg = page.darkmodebg ? page.darkmodebg : DDMBg if theme.background #web_bg + if page.defaultbg || page.darkmodebg + style. + #web_bg{ + background: #{DefaultBg} !important; + background-attachment: local!important; + background-position: center!important; + background-size: cover!important; + background-repeat: no-repeat!important; + } + [data-theme="dark"] + #web_bg{ + background: #{DarkmodeBg} !important; + background-attachment: local!important; + background-position: center!important; + background-size: cover!important; + background-repeat: no-repeat!important; + }
|
在[Blogroot]/themes/butterfly/source/css/_layout
目录下新建一个web-bg.styl
文件,写入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| $web-bg-night = hexo-config('background.darkmode') ? unquote(hexo-config('background.darkmode')) : $web-bg $mobile-bg-day = hexo-config('background.mobileday') ? unquote(hexo-config('background.mobileday')) : $web-bg $mobile-bg-night = hexo-config('background.mobilenight') ? unquote(hexo-config('background.mobilenight')) : $web-bg-night [data-theme="dark"] #web_bg background: $web-bg-night background-attachment: local background-position: center background-size: cover background-repeat: no-repeat @media screen and (max-width: 800px) #web_bg background: $mobile-bg-day !important background-attachment: local !important background-position: center !important background-size: cover !important background-repeat: no-repeat !important [data-theme="dark"] #web_bg background: $mobile-bg-night !important background-attachment: local !important background-position: center !important background-size: cover !important background-repeat: no-repeat !important
|
然后修改一下[Blogroot]/themes/butterfly/source/css/var.styl
中的$web-bg
:
1 2
| -$web-bg = hexo-config('background') && unquote(hexo-config('background')) +$web-bg = hexo-config('background.default') && unquote(hexo-config('background.default'))
|
这样就可以设置多张背景图片了,在主题配置文件[Blogroot]/_config.butterfly.yml
中找到background
配置项,此时就可以配置四个背景了:
1 2 3 4 5
| background: default: darkmode: mobileday: mobilenight:
|
如果要开pjax,就改一下[Blogroot]/themes/butterfly/layout/includes/third-party/pjax.pug
,找到pjaxSelectors
,替换为下面的内容:
1
| - let pjaxSelectors = ['head > title','#config-diff','#body-wrap','#rightside-config-hide','#rightside-config-show','#web_bg','.js-pjax']
|
博客功能魔改
标签外挂
1 2 3
| npm install hexo-butterfly-tag-plugins-plus --save npm uninstall hexo-renderer-marked --save #与外挂标签语法的兼容性较差,卸载 npm install hexo-renderer-markdown-it --save # 安装这个markdown渲染插件
|
- 代码配置
在站点配置文件[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
|
tag_plugins: enable: true priority: 5 issues: false link: placeholder: /img/link.svg CDN: anima: https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css jquery: issues: https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/issues.js iconfont: false carousel: false tag_plugins_css: https://npm.elemecdn.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css
|
PDF显示
1
| npm install hexo-pdf --save
|
数学公式显示
1 2 3
| npm un hexo-renderer-marked --save # 如果有安装这个的话,卸载 npm un hexo-renderer-kramed --save # 如果有安装这个的话,卸载 npm install katex @renbaoshuo/markdown-it-katex #需要安装这个katex插件
|
在主题配置文件[Blogroot]/_config.butterfly.yml
的内容设置中找到Math
部分,启用katex,并设置per_page
参数为false
,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
mathjax: enable: false per_page: false
katex: enable: true per_page: false hide_scrollbar: true
|
katex更轻量化,我推荐使用这种来呈现数学公式,上面的内容就是禁用mathjax,启用katex。
最后,在站点配置文件[Blogroot]/_config.yml
末尾添加如下内容:
1 2 3
| markdown: plugins: - '@renbaoshuo/markdown-it-katex'
|
杂项魔改
导航栏昼夜切换按钮
找到[BlogRoot]/themes/butterfly/layout/includes/header/nav.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 31
| nav#nav //- 导航栏左侧显示LOGO及站名 span#blog-info a(href=url_for('/') title=config.title) if theme.nav.logo img.site-icon(src=url_for(theme.nav.logo)) if theme.nav.display_title span.site-name=config.title //- 导航栏中间显示菜单及文章标题 #menus !=partial('includes/header/menu_item', {}, {cache: true}) center(id="name-container") //- 假设文章标题是动态设置的,这里仅作为占位符 a(id="page-name" href="javascript:scrollToTop()") 文章标题 //- 导航栏右侧显示搜索按钮 #nav-right if (theme.algolia_search.enable || theme.local_search.enable || theme.docsearch.enable) #search-button a.search.faa-parent.animated-hover(title="检索站内任何你想要的信息") svg.faa-tada.icon(style="height:30px;width:30px;fill:currentColor;position:relative;top:6px", aria-hidden="true") use(xlink:href='#icon-sousuo') //- span=' '+_p('search.title')
+ a.sun_moon.faa-parent.animated-hover(onclick='switchNightMode()', title=_p('rightside.night_mode_title') id="nightmode-button") + svg.faa-tada(style="height:30px;width:30px;fill:currentColor;position:relative;top:6px", viewBox='0 0 1024 1024') + use#modeicon(xlink:href='#icon-light') #toggle-menu a.site-page(href="javascript:void(0);") i.fas.fa-bars.fa-fw
|
随后在custom.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
| function switchNightMode() { document .querySelector("body") .insertAdjacentHTML( "beforeend", '<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>' ), setTimeout(function () { document.querySelector("body").classList.contains("DarkMode") ? (document.querySelector("body").classList.remove("DarkMode"), localStorage.setItem("isDark", "0"), document .getElementById("modeicon") .setAttribute("xlink:href", "#icon-light")) : (document.querySelector("body").classList.add("DarkMode"), localStorage.setItem("isDark", "1"), document .getElementById("modeicon") .setAttribute("xlink:href", "#icon-dark")), setTimeout(function () { document.getElementsByClassName( "Cuteen_DarkSky" )[0].style.transition = "opacity 3s"; document.getElementsByClassName("Cuteen_DarkSky")[0].style.opacity = "0"; setTimeout(function () { document.getElementsByClassName("Cuteen_DarkSky")[0].remove(); }, 1e3); }, 2e3); }); const nowMode = document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light"; if (nowMode === "light") { activateDarkMode(); saveToLocal.set("theme", "dark", 2); GLOBAL_CONFIG.Snackbar !== undefined && btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night); document.getElementById("modeicon").setAttribute("xlink:href", "#icon-dark"); } else { activateLightMode(); saveToLocal.set("theme", "light", 2); document.querySelector("body").classList.add("DarkMode"), document .getElementById("modeicon") .setAttribute("xlink:href", "#icon-light"); } typeof utterancesTheme === "function" && utterancesTheme(); typeof FB === "object" && window.loadFBComment(); window.DISQUS && document.getElementById("disqus_thread").children.length && setTimeout(() => window.disqusReset(), 200); }
|
博客加载动画
找到[BlogRoot]/themes/butterfly/layout/includes/loading/fullpage-loading.pug
,修改为如下内容:
1 2 3 4 5 6 7 8 9
| //- 旋转彩虹 及其显示隐藏js逻辑 #loading-box .loader .loader-inner - var i = 0 while i < 5 .loader-line-wrap .loader-line - i++
|
然后修改[BlogRoot]/themes/butterfly/source/css/_layout/loading.styl
中的内容如下:
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| .loader { background: #000; background: radial-gradient(#222, #000); bottom: 0; left: 0; overflow: hidden; position: fixed; right: 0; top: 0; z-index: 99999; }
.loader-inner { bottom: 0; height: 60px; left: 0; margin: auto; position: absolute; right: 0; top: 0; width: 100px; }
.loader-line-wrap { animation: loadspin 2000ms cubic-bezier(.175, .885, .32, 1.275) infinite; box-sizing: border-box; height: 50px; left: 0; overflow: hidden; position: absolute; top: 0; transform-origin: 50% 100%; width: 100px; } .loader-line { border: 4px solid transparent; border-radius: 100%; box-sizing: border-box; height: 100px; left: 0; margin: 0 auto; position: absolute; right: 0; top: 0; width: 100px; } .loader-line-wrap:nth-child(1) { animation-delay: -50ms; } .loader-line-wrap:nth-child(2) { animation-delay: -100ms; } .loader-line-wrap:nth-child(3) { animation-delay: -150ms; } .loader-line-wrap:nth-child(4) { animation-delay: -200ms; } .loader-line-wrap:nth-child(5) { animation-delay: -250ms; }
.loader-line-wrap:nth-child(1) .loader-line { border-color: hsl(0, 80%, 60%); height: 90px; width: 90px; top: 7px; } .loader-line-wrap:nth-child(2) .loader-line { border-color: hsl(60, 80%, 60%); height: 76px; width: 76px; top: 14px; } .loader-line-wrap:nth-child(3) .loader-line { border-color: hsl(120, 80%, 60%); height: 62px; width: 62px; top: 21px; } .loader-line-wrap:nth-child(4) .loader-line { border-color: hsl(180, 80%, 60%); height: 48px; width: 48px; top: 28px; } .loader-line-wrap:nth-child(5) .loader-line { border-color: hsl(240, 80%, 60%); height: 34px; width: 34px; top: 35px; }
@keyframes loadspin { 0%, 15% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
#loading-box &.loaded .loader opacity: 0 z-index: -1000 transition: opacity 0.5s ease, z-index 0s 0.5s
|
最后,在custom.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
| document.addEventListener("DOMContentLoaded", function () { const preloader = { endLoading: function () { document.body.style.overflow = "auto"; document.getElementById("loading-box").classList.add("loaded"); }, initLoading: function () { document.body.style.overflow = ""; document.getElementById("loading-box").classList.remove("loaded"); }, };
if ( document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive" ) { preloader.endLoading(); } else { window.addEventListener("load", preloader.endLoading); }
if (window.theme && window.theme.pjax && window.theme.pjax.enable) { document.addEventListener("pjax:send", preloader.initLoading); document.addEventListener("pjax:complete", preloader.endLoading); } });
|
这样,博客加载动画就完成了。