记录本站使用的主题配置和插件

NexT

先看效果:Markdown 渲染测试

自动生成类别

zthxxx/hexo-directory-category: Automatically add category to Hexo article according to the article file directory.

暗黑模式

Hexo Next 8.x 主题添加可切换的暗黑模式 | Clay 的技术空间

阅读进度显示

next 主题自带的 back2top 和暗黑模式按钮放一起有些违和,遂改用 moon-cake:

image.png

1
npm install hexo-cake-moon-menu --save

_config.next.yml 中添加:

1
2
3
4
5
6
7
8
9
moon_menu:
back2top:
enable: true
icon: fas fa-chevron-up
order: -1
back2bottom:
enable: true
icon: fas fa-chevron-down
order: -2

自定义样式 themes/next/source/css/_custom/moon_cake.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
.moon-menu, .moon-menu-bg, .moon-menu-content {
right: 29px !important;
bottom: 128px !important;
height: 3.4rem !important;
width: 3.4rem !important;
font-size: 1rem !important;
}

.moon-menu {
--moon-cricle: #100F2C !important;
--moon-item-bg-color: #100F2C !important;
}

.moon-menu-item {
left: 0.46em !important;
background-color: #282828;
}

.moon-menu-text {
font-size: 1.1rem !important;
}

.moon-menu-icon {
font-size: 2.1rem !important;
}

themes/next/source/css/main.styl 引用该文件:

1
@import '_custom/moon_cake.css';

themes/next/source/css/_custom/darkmode.styl 中添加:

1
2
3
4
5
6
7
8
.darkmode--activated .moon-menu {
--moon-cricle: #fff !important;
--moon-item-bg-color: #fff !important
}

.darkmode--activated .moon-menu-icon,.darkmode--activated .moon-menu-item,.darkmode--activated .moon-menu-text {
color: #000
}

最终效果:

image.png

鼠标点击特效

  1. themes/next/source 下新建文件 clicklove.js

    1
    !function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);
  2. 修改文件 layout/_scripts/index.njk,在最后添加:

    1
    {{- next_js('clicklove.js') }}

代码折叠

NexT 在 v8.18.0 后已支持代码折叠功能:

1
2
3
4
codeblock:
fold:
enable: true
height: 300

如果是 8.18.0 以前的版本,可以采用以下方案:Hexo 实现代码折叠功能

双向链接支持

uuanqin/hexo-filter-titlebased-link: Transfer wiki links (based on the title) in Markdown files to permalink. 将基于标题的双向链接转换为 Hexo 设定的永久链接。

Callouts 支持

安装插件:

1
2
3
4
# 替换原先的 markdown 渲染器
npm un hexo-renderer-marked --save
npm install hexo-renderer-markdown-it-plus --save
npm install mdit-plugin-callouts --save

在 _config.yml 中添加插件:

1
2
3
4
5
6
7
8
9
# markdown_it_plus 语法渲染插件选项
markdown_it_plus:
plugins:
# Obsidian Callouts
- plugin:
name: mdit-plugin-callouts
enable: true
options:
# this is plugin option

themes/next/source/css 下创建一个_custom文件夹,新建外部 CSS 文件 callout_blocks.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
:root {
--un-ring-offset-shadow: 0 0 transparent;
--un-ring-shadow: 0 0 transparent
}

.custom-callout {
border-left: 3px solid;
border-radius: var(--callout-radius);
box-shadow: var(--un-ring-offset-shadow), var(--un-ring-shadow), var(--un-shadow);
margin: 1rem 0;
padding: 0 !important;
}

:root {
--callout-note: 68, 138, 255;
--callout-abstract: 0, 176, 255;
--callout-info: 0, 184, 212;
--callout-tip: 0, 191, 165;
--callout-success: 8, 185, 78;
--callout-question: 224, 172, 0;
--callout-warning: 255, 145, 0;
--callout-failure: 255, 82, 82;
--callout-danger: 255, 23, 68;
--callout-bug: 245, 0, 87;
--callout-example: 124, 77, 255;
--callout-quote: 158, 158, 158;
--callout-radius: 0px;
--callout-border-opacity: 0.5;
--callout-title-bg-opacity: 0.08
}

.callout-fold:before {
align-self: center;
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="gray" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="chevron-down"><path d="m6 9 6 6 6-6"/></svg>')
}

.callout-fold {
display: flex;
transform: rotate(-90deg);
transition: .5s cubic-bezier(.075, .82, .165, 1)
}

.custom-callout[open] > summary > .callout-fold {
transform: rotate(0deg)
}

.custom-callout > summary {
border-top-left-radius: var(--callout-radius);
border-top-right-radius: var(--callout-radius);
cursor: pointer;
margin: 0;
padding: 1rem
}

.custom-callout > summary::marker {
content: ""
}

.custom-callout > summary:before {
margin-right: .5rem
}

.custom-callout > summary::-webkit-details-marker {
display: none
}

.callout-title {
display: flex;
justify-content: space-between
}

.custom-callout > .callout-body {
background: transparent !important;
border-left: none;
margin: 0 !important;
padding: .5rem 1rem;
position: relative
}

.custom-callout > .callout-body > p {
margin: 8px 0
}

.custom-callout > .callout-body > pre {
margin: 1.25rem -1rem
}

.custom-callout > .callout-body > pre:first-child {
margin-top: -.75rem
}

.custom-callout > .callout-body > pre:last-child {
margin-bottom: -.75rem
}

.custom-callout.note, .custom-callout.seealso {
border-color: rgba(var(--callout-note), var(--callout-border-opacity))
}

.custom-callout.note > summary, .custom-callout.seealso > summary {
background-color: rgba(var(--callout-note), var(--callout-title-bg-opacity))
}

.custom-callout.abstract, .custom-callout.summary, .custom-callout.tldr {
border-color: rgba(var(--callout-abstract), var(--callout-border-opacity))
}

.custom-callout.abstract > summary, .custom-callout.summary > summary, .custom-callout.tldr > summary {
background-color: rgba(var(--callout-abstract), var(--callout-title-bg-opacity))
}

.custom-callout.info, .custom-callout.todo {
border-color: rgba(var(--callout-info), var(--callout-border-opacity))
}

.custom-callout.info > summary, .custom-callout.todo > summary {
background-color: rgba(var(--callout-info), var(--callout-title-bg-opacity))
}

.custom-callout.hint, .custom-callout.important, .custom-callout.tip {
border-color: rgba(var(--callout-tip), var(--callout-border-opacity))
}

.custom-callout.hint > summary, .custom-callout.important > summary, .custom-callout.tip > summary {
background-color: rgba(var(--callout-tip), var(--callout-title-bg-opacity))
}

.custom-callout.check, .custom-callout.done, .custom-callout.success {
border-color: rgba(var(--callout-success), var(--callout-border-opacity))
}

.custom-callout.check > summary, .custom-callout.done > summary, .custom-callout.success > summary {
background-color: rgba(var(--callout-success), var(--callout-title-bg-opacity))
}

.custom-callout.faq, .custom-callout.help, .custom-callout.question {
border-color: rgba(var(--callout-question), var(--callout-border-opacity))
}

.custom-callout.faq > summary, .custom-callout.help > summary, .custom-callout.question > summary {
background-color: rgba(var(--callout-question), var(--callout-title-bg-opacity))
}

.custom-callout.attention, .custom-callout.caution, .custom-callout.warning {
border-color: rgba(var(--callout-warning), var(--callout-border-opacity))
}

.custom-callout.attention > summary, .custom-callout.caution > summary, .custom-callout.warning > summary {
background-color: rgba(var(--callout-warning), var(--callout-title-bg-opacity))
}

.custom-callout.fail, .custom-callout.failure, .custom-callout.missing {
border-color: rgba(var(--callout-failure), var(--callout-border-opacity))
}

.custom-callout.fail > summary, .custom-callout.failure > summary, .custom-callout.missing > summary {
background-color: rgba(var(--callout-failure), var(--callout-title-bg-opacity))
}

.custom-callout.danger, .custom-callout.error {
border-color: rgba(var(--callout-danger), var(--callout-border-opacity))
}

.custom-callout.danger > summary, .custom-callout.error > summary {
background-color: rgba(var(--callout-danger), var(--callout-title-bg-opacity))
}

.custom-callout.bug {
border-color: rgba(var(--callout-bug), var(--callout-border-opacity))
}

.custom-callout.bug > summary {
background-color: rgba(var(--callout-bug), var(--callout-title-bg-opacity))
}

.custom-callout.example {
border-color: rgba(var(--callout-example), var(--callout-border-opacity))
}

.custom-callout.example > summary {
background-color: rgba(var(--callout-example), var(--callout-title-bg-opacity))
}

.custom-callout.cite, .custom-callout.quote {
border-color: rgba(var(--callout-quote), var(--callout-border-opacity))
}

.custom-callout.cite > summary, .custom-callout.quote > summary {
background-color: rgba(var(--callout-quote), var(--callout-title-bg-opacity))
}

.callout-title > .callout-icon + div {
-webkit-box-flex: 1;
-ms-flex: 1 1 0%;
-webkit-flex: 1 1 0%;
flex: 1 1 0%;
margin-left: .25rem
}

.callout-icon {
align-items: center;
color: #000;
display: flex
}

.callout-icon:before {
height: 20px;
width: 20px
}

.custom-callout.attention > .callout-title > .callout-icon:before, .custom-callout.caution > .callout-title > .callout-icon:before, .custom-callout.warning > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23FF9100" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-alert-triangle"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3ZM12 9v4M12 17h.01"/></svg>')
}

.custom-callout.note > .callout-title > .callout-icon:before, .custom-callout.seealso > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23448AFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-pencil"><path d="m18 2 4 4M7.5 20.5 19 9l-4-4L3.5 16.5 2 22z"/></svg>')
}

.custom-callout.abstract > .callout-title > .callout-icon:before, .custom-callout.summary > .callout-title > .callout-icon:before, .custom-callout.tldr > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%2300B0FF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-clipboard-list"><rect x="8" y="2" width="8" height="4" rx="1" ry="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2M12 11h4M12 16h4M8 11h.01M8 16h.01"/></svg>')
}

.custom-callout.info > .callout-title > .callout-icon:before, .custom-callout.todo > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%2300B8D4" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-check-circle-2"><path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10z"/><path d="m9 12 2 2 4-4"/></svg>')
}

.custom-callout.hint > .callout-title > .callout-icon:before, .custom-callout.important > .callout-title > .callout-icon:before, .custom-callout.tip > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%2300BFA5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-flame"><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z"/></svg>')
}

.custom-callout.check > .callout-title > .callout-icon:before, .custom-callout.done > .callout-title > .callout-icon:before, .custom-callout.success > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%2300C853" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-check"><path d="M20 6 9 17l-5-5"/></svg>')
}

.custom-callout.faq > .callout-title > .callout-icon:before, .custom-callout.help > .callout-title > .callout-icon:before, .custom-callout.question > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23E0AC00" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-help-circle"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3M12 17h.01"/></svg>')
}

.custom-callout.fail > .callout-title > .callout-icon:before, .custom-callout.failure > .callout-title > .callout-icon:before, .custom-callout.missing > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23FF5252" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-x"><path d="M18 6 6 18M6 6l12 12"/></svg>')
}

.custom-callout.danger > .callout-title > .callout-icon:before, .custom-callout.error > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23FF1744" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-zap"><path d="M13 2 3 14h9l-1 8 10-12h-9l1-8z"/></svg>')
}

.custom-callout.bug > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23F50057" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-bug"><rect x="8" y="6" width="8" height="14" rx="4"/><path d="m19 7-3 2M5 7l3 2M19 19l-3-2M5 19l3-2M20 13h-4M4 13h4M10 4l1 2M14 4l-1 2"/></svg>')
}

.custom-callout.example > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%237C4DFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-list"><path d="M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"/></svg>')
}

.custom-callout.cite > .callout-title > .callout-icon:before, .custom-callout.quote > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%239E9E9E" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-quote"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.756-2.017-2-2H4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2 1 0 1 0 1 1v1c0 1-1 2-2 2s-1 .008-1 1.031V20c0 1 0 1 1 1zM15 21c3 0 7-1 7-8V5c0-1.25-.757-2.017-2-2h-4c-1.25 0-2 .75-2 1.972V11c0 1.25.75 2 2 2h.75c0 2.25.25 4-2.75 4v3c0 1 0 1 1 1z"/></svg>')
}

/* 找不到关键字则提供默认样式 note 样式 */

.custom-callout > .callout-title > .callout-icon:before, .custom-callout.seealso > .callout-title > .callout-icon:before {
content: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%23448AFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-pencil"><path d="m18 2 4 4M7.5 20.5 19 9l-4-4L3.5 16.5 2 22z"/></svg>')
}

.custom-callout , .custom-callout.seealso {
border-color: rgba(var(--callout-note), var(--callout-border-opacity)); /* 不起作用 */
}

.custom-callout > summary, .custom-callout.seealso > summary {
background-color: rgba(var(--callout-note), var(--callout-title-bg-opacity))
}


/* 标题加粗并着色 */

.custom-callout .callout-title > .callout-icon + div{
font-weight: bold;
color: rgba(var(--callout-note)); /* 默认颜色 */
}

.custom-callout.abstract> .callout-title > .callout-icon + div ,
.custom-callout.summary> .callout-title > .callout-icon + div,
.custom-callout.tldr> .callout-title > .callout-icon + div{
color: rgba(var(--callout-abstract));
}

.custom-callout.info> .callout-title > .callout-icon + div ,
.custom-callout.todo> .callout-title > .callout-icon + div{
color: rgba(var(--callout-info));
}

.custom-callout.hint> .callout-title > .callout-icon + div ,
.custom-callout.important> .callout-title > .callout-icon + div,
.custom-callout.tip> .callout-title > .callout-icon + div{
color: rgba(var(--callout-tip));
}

.custom-callout.check> .callout-title > .callout-icon + div ,
.custom-callout.done> .callout-title > .callout-icon + div,
.custom-callout.success> .callout-title > .callout-icon + div{
color: rgba(var(--callout-success));
}

.custom-callout.question> .callout-title > .callout-icon + div ,
.custom-callout.faq> .callout-title > .callout-icon + div,
.custom-callout.help> .callout-title > .callout-icon + div{
color: rgba(var(--callout-question));
}

.custom-callout.attention> .callout-title > .callout-icon + div ,
.custom-callout.caution> .callout-title > .callout-icon + div,
.custom-callout.warning> .callout-title > .callout-icon + div{
color: rgba(var(--callout-warning));
}

.custom-callout.fail> .callout-title > .callout-icon + div,
.custom-callout.failure> .callout-title > .callout-icon + div,
.custom-callout.missing> .callout-title > .callout-icon + div{
color: rgba(var(--callout-failure));
}

.custom-callout.error> .callout-title > .callout-icon + div ,
.custom-callout.danger> .callout-title > .callout-icon + div
{
color: rgba(var(--callout-danger));
}

.custom-callout.bug> .callout-title > .callout-icon + div{
color: rgba(var(--callout-bug));
}

.custom-callout.example> .callout-title > .callout-icon + div{
color: rgba(var(--callout-example));
}

.custom-callout.cite> .callout-title > .callout-icon + div ,
.custom-callout.quote> .callout-title > .callout-icon + div
{
color: rgba(var(--callout-quote));
}

接着在 themes/next/source/css/main.styl 引用该文件:

1
@import '_custom/callout_blocks.css';

博主也尝试了使用 next 的自定义文件方式,即在 styles.styl 里添加样式,会有显示问题。

CDN 加速

【✅推荐】南方科技大学 CDN 镜像 mirrors.sustech.edu.cn/help/cdnjs.html ,是 cdnjs 的镜像站。

修改 _config.next.yml

1
2
3
4
vendors:
internal: local
plugins: custom
custom_cdn_url: https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/${cdnjs_name}/${version}/${cdnjs_file}

生成站点地图

1
npm install hexo-generator-sitemap --save

在 hexo 站点根目录下,创建站点地图的模板文件 sitemap_template.xml,将以下内容复制到文件中:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for post in posts %}
<url>
<loc>{{ post.permalink | uriencode }}</loc>
{% if post.updated %}
<lastmod>{{ post.updated.toISOString() }}</lastmod>
{% elif post.date %}
<lastmod>{{ post.date.toISOString() }}</lastmod>
{% endif %}
</url>
{% endfor %}
</urlset>

_config.yml 中添加:

1
2
3
sitemap:
path: sitemap.xml
template: ./sitemap_template.xml

页脚添加萌 ICP 备案

在 themes/next/layout/_partials/ 目录下创建 moe_icp.njk 源文件,并添加如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<style>
.moe_icp a {
all: unset; /* 重置所有默认样式 */
text-decoration: none;
}

.moe_icp a:hover {
filter: brightness(1.2);
}
</style>

<div class="moe_icp" style="display: flex; justify-content: center; align-items: center; gap: 10px;">
<a href="https://icp.gov.moe/?keyword=20248869" target="_blank">
<img src="https://img.shields.io/badge/%E8%90%8CICP%E5%A4%8720248869%E5%8F%B7-e22b84" alt="萌ICP备20248869号" style="padding-top: 9px;">
</a>

<a style="color:#e77c8e; display: inline-flex; align-items: center;"
href="https://travel.moe/go.html"
title="异次元之旅-跃迁-我们一起去萌站成员的星球旅行吧!"
target="_blank">
<img src="https://travel.moe/images/icon/icon64pink.png" style="width:24px;height:24px; margin-right: 4px;">
异次元之旅
</a>
</div>

themes/next/layout/_partials/footer.njk 的文件末尾添加以下内容:

1
2
3
{%- if theme.moe_icp.enable %}
{% include 'moe_icp.njk' %}
{%- endif %}

themes/next/_config.yml 添加以下内容:

1
2
3
# 萌备
moe_icp:
enable: true

页脚添加站点运行时间

在 themes/next/layout/_partials/ 目录下创建 runtime.njk 源文件,并添加如下内容:

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
<div id="site-runtime">
<span class="post-meta-item-icon">
<i class="fa fa-clock-o"></i>
</span>
<span id="runtime"></span>
</div>

<script language="javascript">
function isPC() {
var userAgentInfo = navigator.userAgent;
var agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
for (var i = 0; i < agents.length; i++) {
if (userAgentInfo.indexOf(agents[i]) > 0) {
return false;
}
}
return true;
}

function siteTime(openOnPC, start) {
window.setTimeout("siteTime(openOnPC, start)", 1000);
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;

{%- if theme.runtime.start %}
start = new Date("{{ theme.runtime.start }}");
{%- endif %}
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var diff = now - start;

var diffYears = Math.floor(diff / years);
var diffDays = Math.floor((diff / days) - diffYears * 365);
var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);

if (openOnPC) {
document.getElementById("runtime").innerHTML = "本站已运行: " + diffYears + " 年 " + diffDays + " 天 " + diffHours + " 小时 " + diffMinutes + " 分 " + diffSeconds + " 秒";
} else {
document.getElementById("runtime").innerHTML = "本站已运行: " + diffYears + "年 " + diffDays + "天 " + diffHours + "小时 " + diffMinutes + "分 " + diffSeconds + "秒";
}
}

var showOnMobile = {{ theme.runtime.mobile }};
var openOnPC = isPC();
var start = new Date();
siteTime(openOnPC, start);

if (!openOnPC && !showOnMobile) {
document.getElementById('site-runtime').style.display = 'none';
}
</script>

themes/next/layout/_partials/footer.njk 的文件末尾添加以下内容:

1
2
3
{%- if theme.runtime.enable %}
{% include 'runtime.swig' %}
{%- endif %}

themes/next/_config.yml 添加以下内容:

1
2
3
4
5
6
7
8
9
10
# Site Runtime
runtime:
enable: true
# The time of the site started running. If not defined, current time of local time zone will be used.
# You can specify the time zone by adding the `+HOURS` or `-HOURS` format time zone.
# If not specify the time zone, it will use `+0000` as default.
# ex: "2015-06-08 07:24:13 +0800", `+0800` specify that it is the time in the East Eight Time Zone.
start: 2019-11-23 09:00:00 +0800
# Whether to show on the mobile side
mobile: false

参考

Hexo之next主题优化_hexo next首页优化-CSDN博客

Hexo 博客适配 Obsidian 新语法 | 半方池水半方田

Hexo Next 主题详细配置之一 | Clay 的技术空间