Hexo 主题 icarus 4 配置夜间模式 Night Mode

Hexo 主题 icarus 4 配置夜间模式 Night Mode

效果

主页

步骤

新增 night.styl

icarus/source/css 目录下创建 night.sytl 文件(展开显示代码)

night.styl >folded
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
dark-primary-color = rgb(55, 61, 72)
dark-primary-color-hover = rgb(67, 74, 86)
dark-primary-color-active = rgb(44, 49, 58)
dark-font-color = #c0c0c0



#universe
display: none

.navbar-logo,
.footer-logo
.logo-img-dark
display: none

body.night
background: #0e1225

.night
// code highlight (https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/atom-one-dark.min.css)
// navigation bar, cards
.content code
color: rgb(203,186,125)

// night icon changed to fas fa-moon-o
#night-nav #night-icon:before
content: '\f186'

.navbar-menu
background-color: inherit
.navbar-main .navbar-menu .navbar-item
&:hover,
&:focus
color: #ffffff
background-color: dark-primary-color
.navbar,
.card
background-color: rgba(40, 44, 52, 0.5)
backdrop-filter: none
-webkit-backdrop-filter: none

.card
&:hover
background-color: rgba(40, 44, 52, 0.8)

.footer
background-color: rgba(40, 44, 52, 0.5)
backdrop-filter: none
-webkit-backdrop-filter: none

&:before
background-color: rgba(40, 44, 52, 0.5)

// input

.input, .textarea
background-color: dark-primary-color-hover
border-color: dark-primary-color

// message
.message.message-immersive
background-color: #c2c2c2
.message-body
color: #222222
.message.message-immersive.is-info
background-color: #bdc3c8
.message-body
color: #004779
.message.message-immersive.is-warning
background-color: #cbc8ba
.message-body
color: #5b4b00
.message.message-immersive.is-danger
background-color: #c6babe
.message-body
color: #79000f
.message.message-immersive.is-success
background-color: #bfc7c0
.message-body
color: #1e4d1c
.message.message-immersive.is-primary
background-color: #bdc0c9
.message-body
color: #003790





// button

.button.is-primary, .button.is-light, .button.is-small
background-color: dark-primary-color
color: dark-font-color

&:hover, &.is-hovered
color: #ffffff
background-color: dark-primary-color-hover

&:active, &.is-active
color: #ffffff
background-color: dark-primary-color-active

.button.is-white,
.button.is-transparent
background-color: transparent

&:hover
background-color: dark-primary-color !important

.pagination .pagination-next,
.pagination .pagination-previous
.pagination-link:not(.is-current)
color: dark-font-color





// button

.button.is-primary, .button.is-light, .button.is-small
background-color: dark-primary-color
color: dark-font-color

&:hover, &.is-hovered
color: #ffffff
background-color: dark-primary-color-hover

&:active, &.is-active
color: #ffffff
background-color: dark-primary-color-active

.button.is-white,
.button.is-transparent
background-color: transparent

&:hover
background-color: dark-primary-color !important

.pagination .pagination-next,
.pagination .pagination-previous
.pagination-link:not(.is-current)
color: dark-font-color
background-color: dark-primary-color

a
color: dark-font-color

.pagination-link.is-current
background-color: dark-primary-color-hover
border-color: dark-primary-color-hover

// comment

.v .vwrap,
.v .vwrap .vheader .vinput
border-color: dark-primary-color

.v .vwrap .vheader .vinput:focus
border-color: dark-primary-color-hover

.v .vbtn
color: dark-font-color
background-color: dark-primary-color
border-color: dark-primary-color

&:hover
background-color: dark-primary-color-hover

&:active
background-color: dark-primary-color-active

.v .vlist .vcard .vhead .vsys
background-color: dark-primary-color

.v a:hover,
.v .vlist .vcard .vh .vmeta .vat
color: #ffffff

.v .vlist .vcard .vcontent.expand:before
background: -webkit-gradient(linear, left top, left bottom, from(rgba(37, 41, 54, 0)), to(rgba(37, 41, 54, 1)))
background: linear-gradient(180deg, rgba(37, 41, 54, 0), rgba(37, 41, 54, 1))

.v .vlist .vcard .vcontent.expand:after
background: rgba(37, 41, 54, 1)

.v .vlist .vcard .vh,
.v .vlist .vcard .vquote
border-color: dark-primary-color-hover

// font color

body,
strong,
time,
.title,
.footer,
.card,
.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6,
.navbar-item,
.navbar-item.is-active,
.navbar-link,
.menu-list a,
.menu-label,
.level-item,
.input,
.textarea,
.button.is-white,
.button.is-transparent,
.article-licensing,
.v *
color: dark-font-color

.media-content,
.has-text-grey,
.link-muted
color: dark-font-color !important

a
color: rgb(82, 153, 224)

&:hover
color: #ffffff

// quote

.content blockquote,
.article-licensing
background-color: dark-primary-color
border-color: dark-primary-color-hover

.post-copyright
background-color: dark-primary-color
border-color: dark-primary-color-hover

// table

.content table thead td,
.content table thead th
color: dark-font-color

.content table td,
.content table th
border-color: dark-primary-color-hover

// break line

hr
background-color: dark-primary-color-hover

// tags and menus

article.article, article.media

.title:hover a
// override anotherr !important
color: dark-font-color !important

.tag:not(body)
color: dark-font-color
background-color: dark-primary-color

.tag.is-grey
background-color: dark-primary-color-hover

.menu-list a:hover
background-color: dark-primary-color

.menu-list a.is-active
background-color: dark-primary-color-hover

.menu-list li ul
border-color: dark-primary-color

// time line

.timeline .media:last-child:after
background-color: rgb(37, 41, 54)

.timeline
border-color: dark-primary-color-hover

.timeline .media:before
background-color: dark-primary-color-hover

// search box

.searchbox
.searchbox-container,
.searchbox-header,
.searchbox-header .searchbox-input,
.searchbox-header .searchbox-close,
.searchbox-body,
.searchbox-result-section,
.searchbox-result-item
color: dark-font-color
background-color: dark-primary-color
border-color: dark-primary-color-hover

.searchbox-container .searchbox-result-section .searchbox-result-item:hover,
.searchbox-container .searchbox-result-section .searchbox-result-item.active,
.searchbox-container .searchbox-header .searchbox-close:hover
color: #ffffff
background-color: dark-primary-color-hover

// selection

::selection
color: #ffffff
background-color: rgba(52, 109, 167, 0.8)

::-moz-selection
color: #ffffff
background-color: rgba(52, 109, 167, 0.8)

input:-webkit-autofill
-webkit-text-fill-color: dark-font-color !important
box-shadow: 0 0 0px 1000px dark-primary-color inset

.hljs {
display: block;
overflow-x: auto;

padding: 0.5em;
color: #abb2bf;
background: #282c34
}

.hljs-comment, .hljs-quote {
color: #5c6370;
font-style: italic
}

.hljs-doctag, .hljs-keyword, .hljs-formula {
color: #c678dd
}

.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst {
color: #e06c75
}

.hljs-literal {
color: #56b6c2
}

.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta-string {
color: #98c379
}

.hljs-built_in, .hljs-class .hljs-title {
color: #e6c07b
}

.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-class, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number {
color: #d19a66
}

.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title {
color: #61aeee
}

.hljs-emphasis {
font-style: italic
}

.hljs-strong {
font-weight: bold
}

.hljs-link {
text-decoration: underline
}

修改 default.styl 文件

icarus/source/css/default.styl末尾新增@import 'night'

default.styl
1
2
@import 'style'
@import 'night'

新增 night.js 文件

icarus/source/js 目录下创建 night.js 文件

night.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
(function () {
/**

* Icarus 夜间模式 by iMaeGoo
* https://www.imaegoo.com/
*/

var isNight = localStorage.getItem('night');
var nightNav;

function applyNight(value) {
if (value.toString() === 'true') {
document.body.classList.remove('light');
document.body.classList.add('night');
} else {
document.body.classList.remove('night');
document.body.classList.add('light');
}
}

function findNightNav() {
nightNav = document.getElementById('night-nav');
if (!nightNav) {
setTimeout(findNightNav, 100);
} else {
nightNav.addEventListener('click', switchNight);
}
}

function switchNight() {
isNight = isNight ? isNight.toString() !== 'true' : true;
applyNight(isNight);
localStorage.setItem('night', isNight);
}

findNightNav();
isNight && applyNight(isNight);
}());

修改 scripts.jsx

icarus/layout/common/scripts.jsx 中的 return <Fragment></Fragment>里新增:

1
<script src={url_for('/js/night.js')} defer={true}></script>

修改 navbar.jsx

icarus/layout/common/navbar.jsx中的 <div class="navbar-end">下新增:

1
2
3
<a class="navbar-item night" id="night-nav" title="Night Mode" href="javascript:;">
<i class="fas fa-lightbulb" id="night-icon"></i>
</a>

参考感谢

Icarus 夜间模式支持 3.0 了

hexo-theme-icarus 3.0.0 添加夜间模式

Asahi
2020.12.27

Hexo 主题 icarus 4 配置夜间模式 Night Mode

https://blog.asahih.com/hexo-icarus-night-mode/

Author

Asahi

Posted on

2020-12-27

Updated on

2022-09-23

Licensed under