-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories.html
133 lines (110 loc) · 4.74 KB
/
categories.html
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
---
layout: base
title: 分类页面
---
<script type="text/javascript">
var urlString = window.location.href;//获取url
if (urlString.split("?").length <= 1) {
// 没有指定分类
window.location.href = "{{site.url}}";
}
var paramAry = urlString.split("?")[1].split("&");
if (paramAry.length == 1) {
var categoryItem = decodeURI(paramAry[0].split("=")[1]);
var pageNo = 1;
} else if (paramAry.length == 2) {
var categoryItem = decodeURI(paramAry[0].split("=")[1]);
var pageNo = paramAry[1].split("=")[1];
}
var dataStr = '{'+
'{% for cat in site.categories %}'+
'{% if cat[0] != site.categories.first[0] %}'+
','+
'{% endif %}'+
'"{{ cat[0] }}":['+
'{% for post in cat[1] %}'+
'{% if post != cat[1].first %}'+
','+
'{% endif %}'+
'{"url":"{{post.url}}", '+
'"title":"{{post.title}}", '+
{% capture tagIdx %}{{ post.tag | first }}{% endcapture %}
{% if site.logo_list[tagIdx] %}
'"logo":"{{site.logo_list[tagIdx]}}", '+
{% else %}
'"logo":"{{site.resource_url}}/public/images/no-image.png", '+
{% endif %}
'"excerpt": '+
'{% if post.content contains "<!-- more -->" %}'+
'"{{ post.content | split:"<!-- more -->" | first | strip_html | strip_newlines }}"'+
'{% else %}'+
'"{{ post.excerpt | strip_html | truncatewords:100 | strip_newlines }}"'+
'{% endif %}'+
','+
'"date":"{{post.date | date:"%Y-%m-%d"}}"}'+
'{% endfor %}'+
']'+
'{% endfor %}}';
var data = JSON.parse(dataStr),
archieves = data[categoryItem];
$(document).ready(function(){
// 填充导航中的分类信息
$(".breadcrumb .categories").attr("href", urlString).attr("title", "查看 "+categoryItem+" 中的全部文章").text(categoryItem);
var pageSize = {{site.paginate}};
// 渲染文章列表
for (var i = (pageNo-1)*pageSize; i < archieves.length; i++) {
// 渲染满一页的文章就停止
if ( i-(pageNo-1)*pageSize >= pageSize) {break;}
var post = archieves[i];
var articleHtml = '<article class="post"><div class="thumb"><a href="{{site.url}}'+post.url+'" title="'+post.title+'" target="_blank"><img alt="'+post.title+'" src="'+post.logo+'"/></a></div>'+
'<span class="post-cat"><a href="{{site.url}}/categories.html?cat='+categoryItem+'" title="查看 '+categoryItem+' 中的全部文章" target="_blank">'+categoryItem+'</a></span>'+
'<h2><a href="'+post.url+'" title="'+post.title+'" target="_blank" title="'+post.title+'" >'+post.title+'</a></h2>'+
'<div class="entry loop-entry"><p>'+post.excerpt+'</p></div>'+
'<div class="postmeta"><span><i class="icon-calendar"></i> 日期:'+post.date+'</span><span><i class="icon-calendar"></i> 日期:'+post.date+'</span>'+
'<span id="'+post.url+'" class="leancloud_visitors" data-xid="'+post.url+'" data-flag-title="'+post.title+'"><i class="icon-fire"></i> 浏览:<i class="leancloud-visitors-count">0</i> 次</span>'+
'<span><i class="icon-comments"></i> 评论:<i class="valine-comment-count" data-xid="'+post.url+'">0</i> 条</span>'+
'</div></article>';
$(".main").append(articleHtml);
};
// 渲染分页列表
var pageHtml = '<div class="pagenavi">';
if ( pageNo-1 > 0 ) {
if ( pageNo-1 == 1 ) {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'"><span class="page"><<</span></a>';
} else {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'&pageNo='+(pageNo-1)+'"><span class="page"><<</span></a>';
}
} else {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'"><span class="page"><<</span></a>';
}
if ( pageNo == 1 ) {
pageHtml += '<span class="page now-page">1</span>';
} else {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'">1</a>';
}
for (var idx = 2; idx <= Math.ceil(archieves.length/pageSize); idx++) {
if (idx == pageNo) {
pageHtml += '<span class="page now-page">'+idx+'</span>';
} else {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'&pageNo='+idx+'">'+idx+'</a>';
}
}
if (pageNo+1 <= Math.ceil(archieves.length/pageSize)) {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'&pageNo='+(pageNo+1)+'">>></a>';
} else {
pageHtml += '<a href="{{site.url}}/categories.html?cat='+categoryItem+'&pageNo='+Math.ceil(archieves.length/pageSize)+'"><span class="page">>></span></a>';
}
pageHtml += '</div>';
$(".main").append(pageHtml);
});
</script>
<div class="breadcrumb">
<i class="icon-home"></i>
<a href="{{site.url}}" title="{{site.title}}">首页</a> » <a class="categories"></a> »
</div>
<!-- 首页或者分类或者标签页面的模板 -->
<main class="main" role="main">
</main>
<aside class="sidebar">
{% include sidebar.html %}
</aside>