博客搭建与魔改系列教程导航🚥🚥🚥

昼夜切换按钮(带日月动画)

昼夜切换按钮

新建 [Blogroot]\themes\butterfly\layout\includes\custom\sun_moon.pug,写入:

1
2
3
4
5
svg(aria-hidden='true', style='position:absolute; overflow:hidden; width:0; height:0')
symbol#icon-sun(viewBox='0 0 1024 1024')
path(d='M512 64l128 128h192v192l128 128-128 128v192h-192l-128 128-128-128H192V640L64 512l128-128V192h192zM512 288a224 224 0 1 0 0 448 224 224 0 0 0 0-448z', fill='#FFD878')
symbol#icon-moon(viewBox='0 0 1024 1024')
path(d='M611.37 167.08a445.01 445.01 0 0 1-38.4 161.83 477.82 477.82 0 0 1-244.74 244.4 445.14 445.14 0 0 1-161.11 38.06 85.08 85.08 0 0 0-65.07 135.72A462.08 462.08 0 1 0 747.09 102.06a85.08 85.08 0 0 0-135.72 65.02z', fill='#FFB531')

新建 [Blogroot]\themes\butterfly\source\js\sun_moon.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
function btfSwitchTheme(toDark) {
const mode = toDark ? 'dark' : 'light'
const btf = window.btf || {}
const activate = toDark
? (btf.activateDarkMode || window.activateDarkMode)
: (btf.activateLightMode || window.activateLightMode)

if (typeof activate === 'function') activate()
else document.documentElement.setAttribute('data-theme', mode)

const save = btf.saveToLocal || window.saveToLocal
if (save && typeof save.set === 'function') save.set('theme', mode, 2)
else {
try {
localStorage.setItem('theme', JSON.stringify({ value: mode, expiry: Date.now() + 2 * 86400000 }))
} catch (e) {}
}

const themeChange = (window.globalFn || {}).themeChange
if (themeChange) {
Object.keys(themeChange).forEach(key => {
const fn = themeChange[key]
if (typeof fn !== 'function') return
if (key === 'disqus' || key === 'disqusjs') setTimeout(() => fn(mode), 300)
else fn(mode)
})
}
}

function btfSetModeIcons(href) {
document.querySelectorAll('#modeicon').forEach(icon => icon.setAttribute('xlink:href', href))
}

function btfNightToast(toDark) {
const title = toDark ? '关灯啦🌙' : '开灯啦🌞'
const message = toDark ? '当前已成功切换至夜间模式!' : '当前已成功切换至白天模式!'
if (typeof window.Vue === 'function') {
try {
new window.Vue({
data: function () {
this.$notify({
title: title, message: message, position: 'top-left',
offset: 50, showClose: true, type: 'success', duration: 5000
})
}
})
return
} catch (e) {}
}
try {
const btf = window.btf || {}
const gcfg = window.GLOBAL_CONFIG || {}
if (typeof btf.snackbarShow === 'function' && gcfg.Snackbar && typeof window.Snackbar !== 'undefined') {
btf.snackbarShow(title + ' ' + message)
}
} catch (e) {}
}

function switchNightMode() {
const body = document.querySelector('body')
const toDark = document.documentElement.getAttribute('data-theme') !== 'dark'

body.insertAdjacentHTML('beforeend', '<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"><div id="sun"></div><div id="moon"></div></div></div>')

body.classList.toggle('DarkMode', toDark)
try { localStorage.setItem('isDark', toDark ? '1' : '0') } catch (e) {}
btfSetModeIcons(toDark ? '#icon-sun' : '#icon-moon')

const sun = document.getElementById('sun')
const moon = document.getElementById('moon')
sun.style.opacity = toDark ? '1' : '0'
moon.style.opacity = toDark ? '0' : '1'
setTimeout(function () {
sun.style.opacity = toDark ? '0' : '1'
moon.style.opacity = toDark ? '1' : '0'
}, 1000)

btfSwitchTheme(toDark)

setTimeout(function () {
const sky = document.querySelector('.Cuteen_DarkSky')
if (!sky) return
sky.style.transition = 'opacity 3s'
sky.style.opacity = '0'
setTimeout(function () { sky.remove() }, 1000)
}, 2000)

setTimeout(function () { btfNightToast(toDark) }, 2000)

typeof utterancesTheme === 'function' && utterancesTheme()
typeof FB === 'object' && window.loadFBComment()
window.DISQUS && document.getElementById('disqus_thread') && document.getElementById('disqus_thread').children.length && setTimeout(() => window.disqusReset(), 200)
}

function btfSyncModeIcons() {
const isDark = document.documentElement.getAttribute('data-theme') === 'dark'
btfSetModeIcons(isDark ? '#icon-sun' : '#icon-moon')
}

btfSyncModeIcons()
document.addEventListener('DOMContentLoaded', btfSyncModeIcons)
if (window.btf && typeof window.btf.addGlobalFn === 'function') {
window.btf.addGlobalFn('pjaxComplete', btfSyncModeIcons, 'sunMoonIconSync')
}

新建 [Blogroot]\themes\butterfly\source\css\_layout\sun_moon.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
.Cuteen_DarkSky,
.Cuteen_DarkSky:before
content ''
position fixed
left 0
right 0
top 0
bottom 0
z-index 88888888

.Cuteen_DarkSky
background linear-gradient(to top, #f8cd71 0, #5bfde9 80%)
&:before
transition 2s ease all
opacity 0
background linear-gradient(to top, #30cfd0 0, #330867 100%)

.DarkMode
.Cuteen_DarkSky
&:before
opacity 1

.Cuteen_DarkPlanet
z-index 99999999
position fixed
left -50%
top -50%
width 200%
height 200%
animation CuteenPlanetMove 2s cubic-bezier(0.7, 0, 0, 1)
transform-origin center bottom

@keyframes CuteenPlanetMove
0%
transform rotate(0)
to
transform rotate(360deg)

.Cuteen_DarkPlanet
#sun
position absolute
border-radius 100%
left 44%
top 30%
height 6rem
width 6rem
background #ffee94
box-shadow 0 0 40px #ffee94
#moon
position absolute
border-radius 100%
left 44%
top 30%
height 6rem
width 6rem
box-shadow -1.8em 1.8em 0 0.2em #fff

在 [Blogroot]\themes\butterfly\layout\includes\head.pug 最末尾添加:
1
2
3
4
!=fragment_cache('injectHead', function(){return injectHtml(theme.inject.head)})

#myscoll
include ./custom/sun_moon.pug

在 [Blogroot]\themes\butterfly\layout\includes\header\nav.pug 的 #menus 块之后添加(缩进 2 格,与 #menus 同级):
1
2
3
4
//- 暗黑模式按钮
a.sun_moon.faa-parent.animated-hover(onclick='switchNightMode()', title=_p('rightside.night_mode_title') id="nightmode-button")
svg.faa-tada(style="height:25px;width:25px;fill:currentColor;position:relative;top:7px", viewBox='0 0 1024 1024')
use#modeicon(xlink:href='#icon-moon')

把 [Blogroot]\themes\butterfly\layout\includes\rightside.pug 的 when 'darkmode' 分支改成:
1
2
3
4
5
when 'darkmode'
if darkmode.enable && darkmode.button
a.icon-V.hidden(onclick='switchNightMode()', title=_p('rightside.night_mode_title'))
svg(width='25', height='25', viewBox='0 0 1024 1024')
use#modeicon(xlink:href='#icon-moon')

在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
4
5
display_mode: light
darkmode:
enable: true
button: true
autoChangeMode: false

在 [Blogroot]\_config.butterfly.yml 的 inject.bottom 添加:
1
2
3
inject:
bottom:
- <script async src="/js/sun_moon.js"></script> #昼夜转换

导航栏「美化设置」按钮

美化设置按钮

把阿里图标库导出的 JS 放到 [Blogroot]\source\js\ali_font.js,其中要有 #icon-tupian1 这个 symbol。
在 [Blogroot]\themes\butterfly\layout\includes\header\nav.pug 的 #menus 块之后添加:

1
2
3
4
//- 美化设置
a.meihua.faa-parent.animated-hover(onclick="toggleWinbox()" title="美化设置-自定义你的风格" id="meihua-button")
svg.faa-tada.icon(style="height:26px;width:26px;fill:currentColor;position:relative;top:8px" aria-hidden="true")
use(xlink:href='#icon-tupian1')

新建 [Blogroot]\source\js\meihua.js,写入:
1
2
3
4
5
6
7
8
9
10
11
function toggleWinbox() {
var box = document.getElementById('meihua-winbox');
if (box) { box.remove(); return; }
box = document.createElement('div');
box.id = 'meihua-winbox';
box.innerHTML = '<h3>美化设置</h3>' +
'<button onclick="document.documentElement.classList.toggle(\'low-perf\')">切换性能模式</button>' +
'<button onclick="switchNightMode()">切换昼夜</button>' +
'<button onclick="this.parentNode.remove()">关闭</button>';
document.body.appendChild(box);
}

在 [Blogroot]\source\css\custom.css 末尾添加:
1
2
3
4
5
6
7
8
9
10
11
12
#meihua-winbox {
position: fixed;
right: 20px;
top: 80px;
z-index: 10090;
padding: 16px;
border-radius: 12px;
background: rgba(255,255,255,.95);
box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
[data-theme="dark"] #meihua-winbox { background: rgba(30,35,45,.95); color: #fff; }
#meihua-winbox button { display: block; margin: 8px 0; cursor: pointer; }

在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
4
tag_plugins:
enable: true
CDN:
iconfont: /js/ali_font.js

在 [Blogroot]\_config.butterfly.yml 的 inject.bottom 添加:
1
2
3
inject:
bottom:
- <script defer src="/js/meihua.js"></script> #美化设置

导航栏挤不下才切三条杠

导航栏自适应

新建 [Blogroot]\source\js\nav-fit.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
(function () {
var nav, menu, title, search;
var cachedMenuWidth = 0;

function measure() {
if (!menu) return;
var rect = menu.getBoundingClientRect();
if (getComputedStyle(menu).display !== 'none' && rect.width > 0) {
cachedMenuWidth = rect.width;
return;
}
menu.style.setProperty('display', 'block', 'important');
menu.style.setProperty('visibility', 'hidden', 'important');
cachedMenuWidth = menu.getBoundingClientRect().width;
menu.style.removeProperty('display');
menu.style.removeProperty('visibility');
}

function fit() {
if (!nav || !menu || !title || !search) return;
if (window.innerWidth <= 768) return;
if (!cachedMenuWidth) return;
var gap = 14;
var titleRight = title.getBoundingClientRect().right;
var rightReserve = window.innerWidth - search.getBoundingClientRect().left;
var needLeft = 2 * (titleRight + gap) + cachedMenuWidth;
var needRight = cachedMenuWidth + 2 * (rightReserve + gap);
var threshold = Math.max(needLeft, needRight);
nav.classList.toggle('hide-menu', window.innerWidth < threshold);
}

function refresh() {
nav = document.getElementById('nav');
menu = document.querySelector('#nav .menus_items');
title = document.querySelector('#blog-info a');
search = document.getElementById('search-button');
if (!nav || !menu || !title || !search) return;
measure();
fit();
}

function schedule() {
setTimeout(refresh, 0);
requestAnimationFrame(function () { requestAnimationFrame(refresh); });
}

document.addEventListener('DOMContentLoaded', schedule);
if (document.readyState !== 'loading') schedule();
window.addEventListener('load', schedule);
document.addEventListener('pjax:complete', function () { setTimeout(schedule, 80); });
window.addEventListener('resize', function () { setTimeout(fit, 0); });
if (document.fonts && document.fonts.ready) {
document.fonts.ready.then(function () { setTimeout(schedule, 50); });
}
})();

在 [Blogroot]\_config.butterfly.yml 的 inject.bottom 添加:
1
2
3
inject:
bottom:
- <script defer src="/js/nav-fit.js"></script> #导航栏挤不下时才切三条杠

[Blogroot]\_config.butterfly.yml 的 menu 分组写法:
1
2
3
menu:
文章||fas fa-book || hide:
归档: /archives/ || fas fa-archive

文章页顶部波浪

文章页波浪

在 [Blogroot]\themes\butterfly\layout\includes\header\index.pug 的 include ./post-info.pug 后面插入:

1
2
3
4
5
6
7
8
9
10
11
if globalPageType === 'post'
include ./post-info.pug
section.main-hero-waves-area.waves-area
svg.waves-svg(xmlns='http://www.w3.org/2000/svg', xlink='http://www.w3.org/1999/xlink', viewBox='0 24 150 28', preserveAspectRatio='none', shape-rendering='auto')
defs
path#gentle-wave(d='M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z')
g.parallax
use(href='#gentle-wave', x='48', y='0')
use(href='#gentle-wave', x='48', y='3')
use(href='#gentle-wave', x='48', y='5')
use(href='#gentle-wave', x='48', y='7')

在 [Blogroot]\source\css\custom.css 末尾添加:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.main-hero-waves-area { width: 100%; position: absolute; left: 0; bottom: -11px; z-index: 5; }
.waves-area .waves-svg { width: 100%; height: 5rem; }
.parallax > use { animation: move-forever 25s cubic-bezier(.55,.5,.45,.5) infinite; }
.parallax > use:nth-child(1) { animation-delay: -2s; animation-duration: 7s; fill: #f7f9febd; }
.parallax > use:nth-child(2) { animation-delay: -3s; animation-duration: 10s; fill: #f7f9fe82; }
.parallax > use:nth-child(3) { animation-delay: -4s; animation-duration: 13s; fill: #f7f9fe36; }
.parallax > use:nth-child(4) { animation-delay: -5s; animation-duration: 20s; fill: #f7f9fe; }
[data-theme="dark"] .parallax > use:nth-child(1) { fill: #18171dc8; }
[data-theme="dark"] .parallax > use:nth-child(2) { fill: #18171d80; }
[data-theme="dark"] .parallax > use:nth-child(3) { fill: #18171d3e; }
[data-theme="dark"] .parallax > use:nth-child(4) { fill: #18171d; }
@keyframes move-forever {
0% { transform: translate3d(-90px, 0, 0); }
100% { transform: translate3d(85px, 0, 0); }
}
html.low-perf .parallax > use { animation: none !important; }

自定义全屏加载动画

自定义加载动画

把 [Blogroot]\themes\butterfly\layout\includes\loading\fullpage-loading.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
#loading-box(onclick='document.getElementById("loading-box").classList.add("loaded")')
.loading-bg
div.loading-img
.loading-image-dot

script.
const preloader = {
endLoading: () => {
document.body.style.overflow = 'auto';
document.getElementById('loading-box').classList.add("loaded")
},
initLoading: () => {
document.body.style.overflow = '';
document.getElementById('loading-box').classList.remove("loaded")
}
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => setTimeout(preloader.endLoading, 1200))
} else {
setTimeout(preloader.endLoading, 1200)
}

if (!{theme.pjax && theme.pjax.enable}) {
document.addEventListener('pjax:send', () => { preloader.initLoading() })
document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}

把 [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
if hexo-config('preloader')
.loading-bg
display: flex;
width: 100%;
height: 100%;
position: fixed;
background: rgba(255, 255, 255, 0.8);
z-index: 1001;
opacity: 1;
transition: .3s;

#loading-box
.loading-img
width: 100px;
height: 100px;
border-radius: 50%;
margin: auto;
border: 4px solid #f0f0f2;
animation-duration: .3s;
animation-name: loadingAction;
animation-iteration-count: infinite;
animation-direction: alternate;
.loading-image-dot
width: 30px;
height: 30px;
background: #6bdf8f;
position: absolute;
border-radius: 50%;
border: 6px solid #fff;
top: 50%;
left: 50%;
transform: translate(18px, 24px);
&.loaded
.loading-bg
opacity: 0;
z-index: -1000;

@keyframes loadingAction
0% {
opacity: 1;
}
100% {
opacity: .4;
}

在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
4
preloader:
enable: true
source: 3
pace_css_url: /css/progress_bar.css

打赏按钮投币特效

打赏投币

把 [Blogroot]\themes\butterfly\layout\includes\post\reward.pug 整个替换为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
link(rel='stylesheet' href=url_for(theme.CDN.option.coin_css) media="defer" onload="this.media='all'")
.post-reward
button.tip-button.reward-button
span.tip-button__text= _p('donate')
.coin-wrapper
.coin
.coin__middle
.coin__back
.coin__front
.reward-main
ul.reward-all
each item in theme.reward.QR_code
- var clickTo = (item.itemlist||item).link ? (item.itemlist||item).link : (item.itemlist||item).img
li.reward-item
a(href=clickTo target='_blank')
img.post-qr-code-img(src=url_for((item.itemlist||item).img) alt=(item.itemlist||item).text)
.post-qr-code-desc=(item.itemlist||item).text
if theme.reward.coinAudio
- var coinAudio = theme.reward.coinAudio ? url_for(theme.reward.coinAudio) : '/audio/coin.mp3'
audio#coinAudio(src=coinAudio)
script(defer src=url_for(theme.CDN.option.coin_js))

新建 [Blogroot]\source\css\coin.css,写入:
1
2
3
4
5
6
7
.tip-button { position: relative; border: 0; background: none; cursor: pointer; }
.coin-wrapper { position: absolute; left: 50%; top: -10px; width: 40px; height: 40px; }
.coin { width: 100%; height: 100%; transition: transform .6s ease; transform-style: preserve-3d; }
.tip-button:hover .coin { transform: rotateY(180deg) translateY(-6px); }
.reward-main { display: none; position: absolute; z-index: 10; }
.post-reward:hover .reward-main,
.post-reward:focus-within .reward-main { display: block; }

新建 [Blogroot]\source\js\coin.js,写入:
1
2
3
4
5
6
document.addEventListener('click', function (e) {
var btn = e.target.closest('.reward-button');
if (!btn) return;
var audio = document.getElementById('coinAudio');
if (audio) { audio.currentTime = 0; audio.play().catch(function () {}); }
});

把收款码图片放到 [Blogroot]\source\img\,音效放到 [Blogroot]\source\audio\coin.mp3。
在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CDN:
option:
coin_js: /js/coin.js
coin_css: /css/coin.css
reward:
enable: true
text: 投喂作者
coinAudio: /audio/coin.mp3
QR_code:
- img: /img/wechat.png
link: /img/wechat.png
text: 微信
- img: /img/alipay.png
link: /img/alipay.png
text: 支付宝

右下角「直达底部」与右键模式

右下角按钮

在 [Blogroot]\themes\butterfly\layout\includes\rightside.pug 的 mixin rightsideItem(array) 里,在 when 'comment' 分支后面添加:

1
2
3
4
5
6
7
when 'comment'
if commentsJsLoad
a#to_comment(href="#post-comment" title=_p("rightside.scroll_to_comment"))
i.fas.fa-comments
when 'mouse'
button.share(type="button" title='右键模式' onclick="changeMouseMode()")
i.fas.fa-mouse

把同一文件的默认隐藏数组改成:
1
- const hideArray = enable && hide ? hide.split(',') : ['readmode','translate','darkmode','hideAside', 'mouse']

在同一文件 button#go-up 后面添加:
1
2
3
4
5
button#go-up(type="button" title=_p("rightside.back_to_top"))
span.scroll-percent
i.fas.fa-arrow-up
button#go-down(type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)")
i.fas.fa-arrow-down

同一文件 when 'darkmode' 分支用第 11 项的日月 SVG。
changeMouseMode() 由第 6 项的 source/js/rightmenu.js 提供。

音乐馆独立页面

音乐馆页面

在 [Blogroot]\themes\butterfly\layout\page.pug 的 case page.type 里添加分支:

1
2
3
4
5
when 'categories'
include includes/page/categories.pug
+commentLoad
when 'music'
include includes/page/music.pug

把同一文件的页面标题判断改成:
1
2
if top_img === false && page.type != 'music' && page.title
h1.page-title= page.title

新建 [Blogroot]\themes\butterfly\layout\includes\page\music.pug,写入:
1
2
#anMusic-page
meting-js(id="<歌单ID>" server="netease" type="playlist" mutex="true" preload="auto" theme="var(--anzhiyu-main)" order="list")

新建 [Blogroot]\source\music\index.md,写入:
1
2
3
4
5
6
7
---
title: 音乐馆
date: 2024-10-12 00:45:30
type: music
aside: false
comments: false
---

在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
aplayerInject:
enable: true
per_page: true

在 [Blogroot]\_config.butterfly.yml 的 inject.head 和 inject.bottom 添加:
1
2
3
4
5
inject:
head:
- <link rel="stylesheet" href="/css/music.css"> #音乐馆
bottom:
- <script defer src="/js/anzhiyu.js"></script> #音乐馆

自定义 404 页面

自定义 404

新建 [Blogroot]\themes\butterfly\source\404.html,写入:

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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>404 Page Not Found</title>
<style>
body { margin: 0; min-height: 100vh; display: flex; align-items: center;
justify-content: center; background: #1b2838; color: #fff;
font-family: system-ui, sans-serif; text-align: center; }
h1 { font-size: 6rem; margin: 0; letter-spacing: .1em; }
p { opacity: .7; }
a { display: inline-block; margin-top: 24px; padding: 10px 24px;
border: 1px solid #5ea6e5; border-radius: 24px; color: #5ea6e5;
text-decoration: none; }
</style>
</head>
<body>
<div>
<h1>404</h1>
<p>Page Not Found</p>
<a href="/">返回首页</a>
</div>
</body>
</html>

在 [Blogroot]\_config.butterfly.yml 配置:
1
2
3
error_404:
enable: false
subtitle: 'Page Not Found'

节日弹窗与农历计算

节日弹窗

把 Sweetalert2 官方压缩版放到 [Blogroot]\source\js\sweetalert2.all.js。
新建 [Blogroot]\source\js\day.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
(function () {
var queue = [], loading = false;
window.Swal = {
fire: function () {
queue.push(Array.prototype.slice.call(arguments));
if (loading) return;
loading = true;
var s = document.createElement('script');
s.src = '/js/sweetalert2.all.js';
s.onload = function () {
loading = false;
var real = window.Swal;
if (!real || !real.fire) return;
queue.splice(0).forEach(function (args) { real.fire.apply(real, args); });
};
s.onerror = function () { loading = false; queue.length = 0; };
document.head.appendChild(s);
}
};

var table = {
'1-1': '元旦快乐', '5-1': '劳动节快乐',
'10-1': '国庆快乐', '12-25': '圣诞快乐'
};
var d = new Date();
var key = (d.getMonth() + 1) + '-' + d.getDate();
if (table[key]) {
document.addEventListener('DOMContentLoaded', function () {
window.Swal.fire({ title: table[key], text: '今天是个特别的日子', icon: 'info' });
});
}
})();

农历节日需要时把农历库放到 [Blogroot]\source\js\lunar.js,并在 day.js 之前引入。
在 [Blogroot]\_config.butterfly.yml 的 inject.bottom 添加:
1
2
3
4
inject:
bottom:
- <script defer src="/js/lunar.js"></script> # 农历计算
- <script defer src="/js/day.js"></script> # 节日弹窗