配置Icarus主题

版权申明:本文为原创文章,转载请注明原文出处

原文链接:http://blog.pp6f.com/2022/02/09/Hexo/config_Icarus_theme/

本文记录在使用Icarus主题时的一些配置!所有配置 不分先后 遇到随手记录!

索引

Icarus是基于Hexo静态博客生成器的一款主题。
这里主要介绍如何配置Icarus的自定义化。
如果你还没有使用,可以参考我的其他文章 Hexo安装使用Icarus主题使用及问题
可以帮助你从零建设你的个人博客。


配置CDN

_config.icarus.yml找到providers。全部修改为loli

国内网络环境很多国外的cdn被墙,所以需要修改cdn改善访问速度。

_config.icarus.yml
1
2
3
4
5
6
7
providers:
# Name or URL template of the JavaScript and/or stylesheet CDN provider
cdn: loli
# Name or URL template of the webfont CDN provider
fontcdn: loli
# Name or URL of the fontawesome icon font CDN provider
iconcdn: loli

配置highlight主题 代码高亮

首先 在_config.yml中找到highlight 设置enable: true
Hexo提供了2个代码高亮插件 但同时只能开启一个 所以prismjs要设置为false

_config.yml
1
2
3
4
5
6
7
8
9
highlight:
enable: true #是否启动
line_number: true #显示行号
auto_detect: false #自动侦测代码块
tab_replace: ''
wrap: true #如果line_number启用 wrap会自动开启 即使设置false
hljs: false #开启后 代码块的HTML的class添加hljs-前缀
prismjs:
enable: false

_config.icarus.yml中找到article highlight修改theme
可以在 highlight主题列表 找到更多的主题 也可以在 highlight主题预览 预览这些主题

_config.icarus.yml
1
2
3
4
5
6
7
8
article:
# Code highlight settings
highlight:
theme: vs2015 # default | vs2015
# 显示复制代码按钮
clipboard: true
# 代码块的默认折叠状态。可以是"", "folded", "unfolded"
fold: unfolded

修改页面宽度

Icarus初始的页面宽度在PC端浏览很窄,而且使用3列更小。所以需要加宽显示,看起来更为大气!
具体操作:
1.打开themes\icarus\include\style\responsive.styl。按下面的项修改

themes\icarus\include\style\responsive.styl
1
2
3
4
+fullhd()
.is-2-column .container
max-width: $widescreen - 2 * $gap
width: $widescreen - 2 * $gap

2.这可以宽一点 但还不够 继续!
进入themes\icarus\source\css\文件夹,新建一个styl文件。如:brucebin.styl
编辑填入以下代码

brucebin.styl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
screen-tablet = 769px
screen-desktop = 1088px
screen-widescreen = 1280px
screen-fullhd = 1472px
screen-onek = 1700px

@media screen and (min-width: screen-onek)
.container
max-width: 1600px
width: 1600px
.column.is-3-widescreen
width: 20%
.column.is-6-widescreen
width: 60%

3.打开themes\icarus\source\css\style.styl插入以下代码。将我们新建的styl文件引用进去

themes\icarus\source\css\style.styl
1
@import 'brucebin'

至此完成显示宽度的增加 刷新测试下吧!

增加深色模式

增加深色模式

本文给icarus增加一个深色模式。借鉴了imaegooicarus魔改版 和 jeam-xyzicarus修改版。以下使用的一些代码源自于这两位网友!在此表示感谢!
1.增加一个按钮
在导航页增加一个按钮。打开themes\icarus\layout\common\navbar.jsx。增加以下代码 复制时清除前面的加号

themes\icarus\layout\common\navbar.jsx >folded
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
                    <div class="navbar-end">
+ <a class="navbar-item night" id="night-nav" title="Night Mode" href="javascript:;">
+ <i class="fas fa-lightbulb" id="night-icon"></i>
+ </a>
{Object.keys(links).length ? <Fragment>
{Object.keys(links).map(name => {
const link = links[name];
return <a class="navbar-item" target="_blank" rel="noopener" title={name} href={link.url}>
{link.icon ? <i class={link.icon}></i> : name}
</a>;
})}
</Fragment> : null}
{showToc ? <a class="navbar-item is-hidden-tablet catalogue" title={tocTitle} href="javascript:;">
<i class="fas fa-list-ul"></i>
</a> : null}
{showSearch ? <a class="navbar-item search" title={searchTitle} href="javascript:;">
<i class="fas fa-search"></i>
</a> : null}
</div>

2.新建一个js文件
创建文件themes\icarus\source\js\night.js。代码如下

themes\icarus\source\js\night.js >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
(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);
}());

3.引用js文件
打开themes/icarus/layout/common/scripts.jsx文件。增加以下代码 复制时清除前面的加号

themes/icarus/layout/common/scripts.jsx >folded
1
2
3
4
5
6
7
8
9
10
11
        return <Fragment>
<script src={cdn('jquery', '3.3.1', 'dist/jquery.min.js')}></script>
<script src={cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')}></script>
{clipboard && <script src={cdn('clipboard', '2.0.4', 'dist/clipboard.min.js')} defer></script>}
<script dangerouslySetInnerHTML={{ __html: `moment.locale("${language}");` }}></script>
<script dangerouslySetInnerHTML={{ __html: embeddedConfig }}></script>
<script src={url_for('/js/column.js')}></script>
<Plugins site={site} config={config} page={page} helper={helper} head={false} />
<script src={url_for('/js/main.js')} defer></script>
+ <script src={url_for( '/js/night.js' )} defer={ true }></script>
</Fragment>;

4.新建一个styl文件
创建文件themes/icarus/source/css/night.styl。代码如下

themes/icarus/source/css/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
}

5.引用styl文件
打开themes/icarus/source/css/style.styl文件。插入以下代码

themes/icarus/source/css/style.styl >folded
1
@import 'night'

增加深色logo图标

1.增加导航页logo深色图标
打开themes\icarus\layout\common\navbar.jsx 增减以下代码

themes\icarus\layout\common\navbar.jsx >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
class Navbar extends Component {
render() {
const {
logo,
logoUrl,
+ logoDark,
+ logoDarkUrl,
siteUrl,
siteTitle,
menu,
links,
showToc,
tocTitle,
showSearch,
searchTitle
} = this.props;

let navbarLogo = '';
if (logo) {
if (logo.text) {
navbarLogo = logo.text;
} else {
- navbarLogo = <img src={logoUrl} alt={siteTitle} height="28" />;
+ navbarLogo = [
+ <img class="logo-img" src={logoUrl} alt={siteTitle} height="28" />,
+ <img class="logo-img-dark" src={logoDarkUrl} alt={siteTitle} height="28" />
];
}
} else {
navbarLogo = siteTitle;
}

...

module.exports = cacheComponent(Navbar, 'common.navbar', props => {
const { config, helper, page } = props;
const { url_for, _p, __ } = helper;
- const { logo, title, navbar, widgets, search } = config;
+ const { logo, logoDark, title, navbar, widgets, search } = config;

const hasTocWidget = Array.isArray(widgets) && widgets.find(widget => widget.type === 'toc');
const showToc = (config.toc === true || page.toc) && hasTocWidget && ['page', 'post'].includes(page.layout);

const menu = {};
if (navbar && navbar.menu) {
const pageUrl = typeof page.path !== 'undefined' ? url_for(page.path) : '';
Object.keys(navbar.menu).forEach(name => {
const url = url_for(navbar.menu[name]);
const active = isSameLink(url, pageUrl);
menu[name] = { url, active };
});
}

const links = {};
if (navbar && navbar.links) {
Object.keys(navbar.links).forEach(name => {
const link = navbar.links[name];
links[name] = {
url: url_for(typeof link === 'string' ? link : link.url),
icon: link.icon
};
});
}

return {
logo,
logoUrl: url_for(logo),
+ logoDark,
+ logoDarkUrl: url_for(logoDark),
siteUrl: url_for('/'),
siteTitle: title,
menu,
links,
showToc,
tocTitle: _p('widget.catalogue', Infinity),
showSearch: search && search.type,
searchTitle: __('search.search')
};
});

2.增加脚页logo深色图标
打开themes\icarus\layout\common\footer.jsx 增减以下代码

themes\icarus\layout\common\footer.jsx >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
class Footer extends Component {
render() {
const {
logo,
logoUrl,
+ logoDark,
+ logoDarkUrl,
siteUrl,
siteTitle,
siteYear,
author,
links,
showVisitorCounter,
visitorCounterTitle
} = this.props;

let footerLogo = '';
if (logo) {
if (logo.text) {
footerLogo = logo.text;
} else {
- footerLogo = <img src={logoUrl} alt={siteTitle} height="28" />;
+ footerLogo = [
+ <img class="logo-img" src={logoUrl} alt={siteTitle} height="28" />,
+ <img class="logo-img-dark" src={logoDarkUrl} alt={siteTitle} height="28" />
+ ];
}
} else {
footerLogo = siteTitle;
}

...

module.exports = cacheComponent(Footer, 'common.footer', props => {
const { config, helper } = props;
const { url_for, _p, date } = helper;
- const { logo, title, author, footer, plugins } = config;
+ const { logo, logoDark, title, author, footer, plugins } = config;

const links = {};
if (footer && footer.links) {
Object.keys(footer.links).forEach(name => {
const link = footer.links[name];
links[name] = {
url: url_for(typeof link === 'string' ? link : link.url),
icon: link.icon
};
});
}

return {
logo,
logoUrl: url_for(logo),
+ logoDark,
+ logoDarkUrl: url_for(logoDark),
siteUrl: url_for('/'),
siteTitle: title,
siteYear: date(new Date(), 'YYYY'),
author,
links,
showVisitorCounter: plugins && plugins.busuanzi === true,
visitorCounterTitle: _p('plugin.visitor_count', '<span id="busuanzi_value_site_uv">0</span>')
};
});

3.增加css代码
打开themes\icarus\source\css\night.styl 增加以下代码

themes\icarus\source\css\night.styl >folded
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.night
.content code
color: rgb(203,186,125)

#night-nav #night-icon:before
content: '\f186'

+ // logo
+ .navbar-logo,
+ .footer-logo
+ .logo-img
+ display: none
+ .logo-img-dark
+ display: inline-block

4.增加深色模式的logo图标
制作一个深色模式显示的logo图标,存放在themes\icarus\source\img\ 命名为 logo-dark.png
5.修改配置文件
打开_config.icarus.yml配置文件,增加以下代码。

_config.icarus.yml >folded
1
2
3
4
5
6
7
# Version of the configuration file
version: 5.0.0
# Icarus theme variant, can be "default" or "cyberpunk"
variant: default
# Path or URL to the website's logo
logo: /img/logo.png
+logoDark: /img/logo-dark.png

提示
在复制以上代码时 切忌 删除代码前的"+"
深色模式覆盖不完全 未经严谨的筛查 如有遗漏 可以留言或自行检查

文章分享按钮

_config.icarus.yml找到 share 进行配置。可以参考Icarus提供的文档

1
2
3
4
5
6
# Share plugin configurations
# 分享按钮
share:
type: sharethis
# URL to the ShareThis share plugin script
install_url: ''

修改在手机页面宽度

打开themes\icarus\include\style\responsive.styl 修改padding的值

themes\icarus\include\style\responsive.styl
1
2
3
+mobile()
.section
padding: 0.5rem 0.1rem

在手机页面隐藏小部件

打开themes\icarus\include\style\responsive.styl 在+mobile()增加一下代码

themes\icarus\include\style\responsive.styl
1
2
3
4
5
 +mobile()
.section
padding: 0.5rem 0.1rem
+ .order-1 .card.widget
+ display: none

修改Icarus主题字体

  • 打开themes\icarus\include\style\base.styl 修改$family-sans-serif 的值
  • 默认值(Ubuntu, Roboto, 'Open Sans', 'Microsoft YaHei', sans-serif)
  • 修改为(-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji")

修改code背景颜色

  • 打开themes\icarus\include\style\article.styl 找到.article .code 添加background-color: #f5f5f5
    themes\icarus\include\style\article.styl
    1
    2
    3
    &.article
    code
    background-color: #f5f5f5

给文章增加 原创/转载 标签

  • 给每篇文章加上 原创/转载 的标签
  1. 找到themes\icarus\layout\common\article.jsx增删以下代码

    themes\icarus\layout\common\article.jsx >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
        const moment = require('moment');
    const { Component, Fragment } = require('inferno');
    const Share = require('./share');
    const Donates = require('./donates');
    const Comment = require('./comment');
    const ArticleLicensing = require('hexo-component-inferno/lib/view/misc/article_licensing');
    + const CopyRight = require('./copyright');

    .../* 省略代码 */

    render() {
    const { config, helper, page, index } = this.props;
    const { article, plugins } = config;
    - const { url_for, date, date_xml, __, _p } = helper;
    + const { url_for, date, date_xml, __, _p, is_post } = helper;

    const indexLaunguage = config.language || 'en';
    const language = page.lang || page.language || config.language || 'en';
    const cover = page.cover ? url_for(page.cover) : null;
    const updateTime = article && article.update_time !== undefined ? article.update_time : true;
    const isUpdated = page.updated && !moment(page.date).isSame(moment(page.updated));
    const shouldShowUpdated = page.updated && ((updateTime === 'auto' && isUpdated) || updateTime === true);

    + const copy = page.copy_from ? url_for(page.copy_from) : null;

    .../* 省略代码 */

    + {/* 原创or转载 */}
    + <span class={`level-item copyright article-title type-${copy ? '1' : '2'}`}>{copy ? '转载' : '原创'}</span>
    {/* Creation Date */}
    {page.date && <span class="level-item" dangerouslySetInnerHTML={{
    __html: _p('article.created_at', `<time dateTime="${date_xml(page.date)}" title="${new Date(page.date).toLocaleString()}">${date(page.date)}</time>`)
    }}></span>}

    .../* 省略代码 */

    {/* Title */}
    {page.title !== '' ? <h1 class="title is-3 is-size-4-mobile">
    {index ? <a class="link-muted" href={url_for(page.link || page.path)}>{page.title}</a> : page.title}
    </h1> : null}
    + { /* 版权声明 */}
    + {is_post() ? <CopyRight config={config} page={page} helper={helper} /> : null}





  2. 新建themes\icarus\layout\common\copyright.jsx文件 输入以下代码

    themes\icarus\layout\common\copyright.jsx >folded
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    const { Component } = require('inferno');

    module.exports = class extends Component {
    render() {
    const { page, config } = this.props;
    const { article } = config;

    const isCopy = page.copy_from // 是否为转载的文章
    const url = isCopy ? page.copy_from : page.permalink // 来源链接地址

    if (article.copyright == 'false') {
    return null;
    }
    return <div class={'copyright article-block ' + (isCopy ? 'type-1' : 'type-2') }>
    { !isCopy ? <p>版权申明:本文为原创文章,转载请注明原文出处</p> : null }
    <p>原文链接:<a href={ url } target="_blank">{ url }</a></p>
    </div>;
    }
    };
  3. 新建themes\icarus\include\style\copyright.styl文件 输入以下代码

    themes\icarus\include\style\copyright.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
    $copyright-color-1 ?= #74cf59
    $copyright-color-2 ?= #ca0c16
    $copyright-background-color-1 ?= #eaf9e3
    $copyright-background-color-2 ?= #f9ecec

    .copyright
    &.article-title
    padding: 2px 5px
    border-radius: 3px
    &.type-1
    color: $copyright-color-1
    background-color: $copyright-background-color-1
    &.type-2
    color: $copyright-color-2
    background-color: $copyright-background-color-2
    &.article-block
    padding: 0.4em 0.8em
    margin-bottom: 1em
    border-radius: 0.3rem
    border-left: 5px solid #ca0c16
    P
    word-wrap: break-word
    word-break: break-all
    overflow: hidden
    &.type-1
    border-left: 5px solid $copyright-color-1
    background-color: $copyright-background-color-1
    &.type-2
    border-left: 5px solid $copyright-color-2
    background-color: $copyright-background-color-2
  4. 引用styl文件 打开themes\icarus\source\css\style.styl 追加以下代码

    themes\icarus\source\css\style.styl >folded
    1
    2
    3
    4
    ...

    @import '../../include/style/copyright'

  5. 添加好以上代码后 现在介绍如何使用
    在每篇的文章markdown文件的头 指定copy_from项的连接 即为转载文章 如果不指定copy_from则表示原创文章

     # 转载文章 不指定则是原创文章
     copy_from: https://blog.pp6f.com/
    

修改busuanzi显示uv和pv

  • 增加显示PV
  1. 编辑themes\icarus\layout\common\footer.jsx 修改以下代码
    themes\icarus\layout\common\footer.jsx
    1
    2
    -        visitorCounterTitle: _p('plugin.visitor_count', '<span id="busuanzi_value_site_uv">0</span>')
    + visitorCounterTitle: _p('plugin.visitor_count', '<span id="busuanzi_value_site_uv">0</span>') + _p('plugin.visit_count', ', <span id="busuanzi_value_site_pv">0</span>')
  2. 编辑themes\icarus\layout\common\scripts.jsx 增添以下代码
    themes\icarus\layout\common\scripts.jsx >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
    +        // busuanzi
    + const busuanzi_init = `if (${config.plugins.busuanzi} == true) {
    + $(document).ready(function () {
    + var int = setInterval(fixCount, 100);
    + var uvOffSet = parseInt(${config.busuanzi.site_uv_offset | 0});
    + var pvOffSet = parseInt(${config.busuanzi.site_pv_offset | 0});
    +
    + function fixCount() {
    + var realUv = parseInt($("#busuanzi_value_site_uv").html())
    + var realPv = parseInt($("#busuanzi_value_site_pv").html())
    + if ($("#busuanzi_container_site_uv").css("display") != "none" && realUv > 0) {
    + clearInterval(int);
    + $("#busuanzi_value_site_uv").html(realUv + uvOffSet);
    + $("#busuanzi_value_site_pv").html(realPv + pvOffSet);
    + }
    + }
    + });
    + }`;

    return <Fragment>
    <script src={cdn('jquery', '3.3.1', 'dist/jquery.min.js')}></script>
    <script src={cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')}></script>
    {clipboard && <script src={cdn('clipboard', '2.0.4', 'dist/clipboard.min.js')} defer></script>}
    <script dangerouslySetInnerHTML={{ __html: `moment.locale("${language}");` }}></script>
    <script dangerouslySetInnerHTML={{ __html: embeddedConfig }}></script>
    <script src={url_for('/js/column.js')}></script>
    <Plugins site={site} config={config} page={page} helper={helper} head={false} />
    <script src={url_for('/js/main.js')} defer></script>
    <script src={url_for( '/js/night.js' )} defer={ true }></script>
    + <script dangerouslySetInnerHTML={{ __html: busuanzi_init }}></script> {/* busuanzi */}
    </Fragment>;
  3. 打开博客根目录的_config.yml 添加以下代码
    _config.yml
    1
    2
    3
    busuanzi:
    site_uv_offset: 100 # 初始uv值
    site_pv_offset: 200 # 初始pv值

作者

Bruce

发布于

2022-02-09

更新于

2023-03-10

许可协议

评论