我的博客采用的是: 标签简单分3类,用标签代替任何 【更细分的分类】

一. Hexo 自动生成 Tag Cloud 标签云页面

/layout/.../tags.ejs 添加:

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
<% if (page.path === "tags/index.html"){ %>
<hr>
<br>
<%- list_categories({
depth: 1,
}) %>
<div class="tags">
<%- tagcloud({
min_font: 16,
max_font: 35,
amount: 999,
color: true,
start_color: 'gray',
end_color: 'black',
}) %>
</div>
<style>
.category-list li{
display: inline-block;
margin: 0 1em .5em 0;
padding: 4px;
border: 1px solid lightgray;
font-size: 1.2em;
}
.category-list a {
color: gray;
}
.category-list-item:hover a {
color: gray;
text-decoration: none;
font-weight: bold;
}
.category-list-count {
margin-left: 2px;
font-size: .9em;
}
.article-entry ul li:before{
display: none;
}
.article-inner {
text-align: center;
}
.tags {
max-width: 40em;
margin: 2em auto;
margin-top: 0em;
}
.tags a {
margin-right: 1em;
border-bottom: 1px solid gray;
line-height: 65px;
white-space: nowrap;
}
.tags a:hover {
border-bottom: 2px solid black;
font-style: italic;
text-decoration: none;
}
</style>
<% } %>

二. 彩色标签云 (这种方式会让原来的样式消失)

修改 tagcloud部分如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<%- tagcloud({ // TODO: remember to fix this.
min_font: 16,
max_font: 40,
amount: 999,
color: true,
start_color: 'gray',
end_color: 'red',
}) %>
<script type="text/javascript">
var list = document.querySelectorAll('.tagscloud a');
Array.prototype.forEach.call(list, (item, index) => {
//item.style.fontSize = Math.floor(Math.random() * 29 + 12) + 'px';//12 ~ 40
//item.style.color = 'rgb(' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ', ' + Math.floor(Math.random() * 201) + ')';// 0,0,0 -> 200,200,200
S = "90"; //wa kao, 直接写 "100%,100%)"; 就是不行,非得用个变量 =。=
L = "49"; //莫非重载函数只有 全是变量和全是常量两个?
item.style.color = "hsl(" + Math.round(Math.random() * 360) + "," + S + '%,' + L + '%)';
});
</script>