适配版本

如果您需要定制欢迎语音

  • 主题配置文件_config.anzhiyu.yml Inject配置项 和 添加相关配置项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Inject
# Insert the code to head (before '</head>' tag) and the bottom (before '</body>' tag)
# 插入代码到头部 </head> 之前 和 底部 </body> 之前
inject:
head:
# 自定义css
# 弹窗
- <script async src="https://npm.onmicrosoft.cn/naokuo-blog@1.2.12/js/SAO-Notify.js"></script>

bottom:
# 自定义js

# 网页背景音乐
AUDIO_Background:
enable: true # 总开关
audio_Bg: 'https://cdn.cbd.int/naokuo-blog@1.2.12/audio/audio_Bg.wav'
  • 在路径themes/anzhiyu/layout/includes/layout.pug 添加
1
2
3
4
5
6
7
8
9
10
11
doctype html
html(lang=config.language data-theme=theme.display_mode class=htmlClassHideAside)
head
include ./head.pug
body(data-type="anzhiyu")
#web_bg
#an_music_bg
+ if theme.AUDIO_Background.enable
+ - var audioBg = theme.AUDIO_Background.audio_Bg
+ #Audio-Background
+ audio#Audio-Background_Bg(src=audioBg)
  • 创建CSS隐藏音频按钮
1
2
#Audio-Background
display: none

本站的sw-rules.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* @see https://kmar.top/posts/b70ec88f/
*/

module.exports.config = {
/**
* 与 ServiceWorker 有关的配置项
* 若想禁止插件自动生成 sw,此项填 false 即可
* @type ?Object|boolean
*/
serviceWorker: {
cacheName: "NaoKuoBlogCache"
},
register: {
onerror: undefined
},
dom: {
onsuccess: () => {
caches.match('https://id.v3/').then(function (response) {
if (response) {
// 如果找到了匹配的缓存响应
response.json().then(function (data) {
// 弹窗来自:https://akilar.top/posts/d0d69f76/
SAONotify && SAONotify('更新通知', `已刷新缓存,更新为${data.global + "." + data.local}版本最新内容`);
});
} else {
console.info('未找到匹配的缓存响应');
}
}).catch(function (error) {
console.error('缓存匹配出错:', error);
});
},
},
json: {
merge: ['page', 'archives', 'categories', 'tags']
},
external: {
stable: [
/^https:\/\/npm\.elemecdn\.com\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
/^https:\/\/npm\.onmicrosoft\.cn\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
/^https:\/\/cdn\.cbd\.int\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
/^https:\/\/cdn\.jsdelivr\.net\/npm\/[^/@]+\@[^/@]+\/[^/]+\/[^/]+$/,
],
replacer: srcUrl => {
if (srcUrl.startsWith('https://npm.elemecdn.com')) {
const url = new URL(srcUrl)
return [
srcUrl,
`https://npm.onmicrosoft.cn` + url.pathname,
`https://cdn.cbd.int` + url.pathname,
`https://cdn.jsdelivr.net/npm` + url.pathname,
`https://unpkg.com` + url.pathname
]
} else {
return srcUrl
}
}
}
};

/**
* 缓存列表
* @param clean 清理全站时是否删除其缓存
* @param match {function(URL)} 匹配规则
* 更多:/\/|\.(js|html|css|woff2|woff|ttf|cur)$/
*/
module.exports.cacheRules = {
simple: {
clean: true,
search: false,
match: (url, $eject) => {
const allowedHost = $eject.domain;
return url.host === allowedHost && url.pathname.match(/(\.(js|css|json)|\/)$/)
}
},
cdn: {
clean: true,
match: url =>
[
"cdn.cbd.int",
"lf26-cdn-tos.bytecdntp.com",
"lf6-cdn-tos.bytecdntp.com",
"lf3-cdn-tos.bytecdntp.com",
"lf9-cdn-tos.bytecdntp.com",
"cdn.staticfile.org",
"npm.elemecdn.com",
"npm.onmicrosoft.cn",
"fonts.gstatic.com",
"font.onmicrosoft.cn"
].includes(url.host) && url.pathname.match(/\.(js|css|woff2|woff|ttf|cur)$/)
},
img: {
clean: true,
match: (url, $eject) => {
const allowedHost = $eject.domain;
return url.host === allowedHost && url.pathname.match(/(.*?)\.(png|jpe?g|svg|webp|gif|bmp|psd|tiff|tga|ico|eps)/)
}
}
// ,
// thirdparty: {
// clean: true,
// match: function(url) {
// return url.host === "unpkg.com" && url.pathname.match(/\.(png|webp)$/)
// }
// }
};

/**
* 获取一个 URL 对应的备用 URL 列表,访问顺序按列表顺序,所有 URL 访问时参数一致
* @param srcUrl {string} 原始 URL
* @return {{list: string[], timeout: number}} 返回 null 或不返回表示对该 URL 不启用该功能。timeout 为超时时间(ms),list 为 URL 列表,列表不包含原始 URL 表示去除原始访问
*/
module.exports.getSpareUrls = srcUrl => {
if (srcUrl.startsWith("https://npm.elemecdn.com")) {
return {
timeout: 3000,
list: [srcUrl, "https://cdn.cbd.int/".concat(new URL(srcUrl).pathname),
"https://cdn.jsdelivr.net/npm/".concat(new URL(srcUrl).pathname)
]
};
}
};

/**
* 获取要插入到 sw 中的变量或常量
* @param hexo hexo 对象
* @param rules 合并后的 sw-rules 对象
* @return {Object} 要插入的键值对
*/
module.exports.ejectValues = (hexo, rules) => {
return {
domain: {
prefix: "const",
value: new URL(hexo.config.url).host
}
};
};


/**
* @param request {Request}
* @return {boolean}
*/
module.exports.skipRequest = request => request.url.startsWith("https://i0.hdslb.com") ||
request.url.startsWith('https://meting.qjqq.cn') ||
request.url.startsWith('https://api.i-meto.com');