-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtag.hbs
78 lines (76 loc) · 1.96 KB
/
tag.hbs
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
{{!< default}}
<main id="tag" class="site-main wow fadeIn" data-wow-duration=".8s" role="main">
<ul class="tags">
{{#get "posts" limit="all" include="count" }}
<li class="_all">
<a href="/tag">
show all
<span>{{posts.length}}</span>
</a>
</li>
{{/get}}
{{#get "tags" limit="all" include="count.posts" order="count.posts desc" }}
{{#foreach tags}}
{{#if count.posts}}
<li class="{{slug}}">
<a href="/tag/{{slug}}" >
{{name}}
<span>{{count.posts}}</span>
</a>
</li>
{{/if}}
{{/foreach}}
{{/get}}
</ul>
<ul class="article-list" style="display: none;">
{{!-- 显示当前标签 --}}
{{#if tag}}
{{#foreach posts }}
<li class="year">{{date format='YYYY'}}</li>
<li class="item">
<span class="item_time">{{date format='MM'}}月{{date format='DD'}}日</span>
<a class="item_title" href="{{url}}">{{title}}</a>
</li>
{{/foreach}}
{{/if}}
{{!-- 显示全部 --}}
{{#unless tag}}
{{#get "posts"}}
{{#foreach posts limit="all" include="count.posts" order="count.posts desc" }}
<li class="year">{{date format='YYYY'}}</li>
<li class="item">
<span class="item_time">{{date format='MM'}}月{{date format='DD'}}日</span>
<a class="item_title" href="{{url}}">{{title}}</a>
</li>
{{/foreach}}
{{/get}}
{{/unless}}
</ul>
</main>
<script>
let years = $(".article-list .year");
var pr_year = 0;
for (var i = 0; i < years.length; i++) {
var now_year = $(years[i]).html();
if (now_year != pr_year) {
pr_year = now_year;
} else {
$(years[i]).remove()
}
}
$(".article-list").show()
function getTag() {
let urlArr = window.location.pathname.split("/");
if (urlArr.length > 3) {
return urlArr[2]
} else {
return false
}
}
var tag = getTag();
if (tag) {
$("." + tag).addClass("active")
} else {
$("._all").addClass("active")
}
</script>