-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcategories.html
More file actions
68 lines (58 loc) · 1.7 KB
/
categories.html
File metadata and controls
68 lines (58 loc) · 1.7 KB
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
---
layout: page
title: 分类
nav: category
description: 文章分类
permalink: /categories/
---
<div class="tag-list">
{% for category in site.categories %}
<a href="#{{ category | first }}">{{ category | first }} ({{ category | last | size }})</a>
{% endfor %}
</div>
<div class="category-list">
{% for category in site.categories reversed %}
<div id="{{ category | first }}">
<h3 class="m-list__title"><i class="icon iconfont icon-folder"></i>{{ category | first }}</h3>
<ul class="m-list">
{% for post in category.last %}
<li class="list-item-inline" data-qid="{{post.qid}}">
<a href="{{site.base_path}}{{ post.url }}">
{% if post.qid %}
{{ post.qid }}.
{% endif %}
{{ post.title }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endfor %}
</ul>
<script>
function qid_to_int(qid){
try{
qid = qid.replace('offer_', '');
if(qid.indexOf('.') == -1){
return parseInt(qid);
}else{
let items = qid.split('.');
return parseInt(items[0]) * 100 + parseInt(items[1]);
}
}catch(e){
return 0;
}
}
// sort by qid
let categories = document.querySelectorAll(".m-list");
for(let i=0;i<categories.length;i++){
let ul = categories[i];
let list = ul.querySelectorAll("li");
Array.from(list).sort(function(a, b){
let aqid = a.dataset.qid;
let bqid = b.dataset.qid;
return qid_to_int(aqid) - qid_to_int(bqid);
}).forEach(function(li){
ul.appendChild(li);
});
}
</script>