hexo-theme-icarus 分类排序

hexo-theme-icarus 分类排序

themes\icarus\layout\categories.ejs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// map 前先进行排序
return categories.sort((a, b) => {
// 获取不到权重就使用缺省值 99,缺省值应该比权重最大值还要大
return get_config('categort_weight.' + a.name, 99)
- get_config('categort_weight.' + b.name, 99);
}).map(category => {
let result = `<li>
<a class="level is-marginless" href="${category.url}">
<span class="level-start">
<span class="level-item">${category.name}</span>
</span>
<span class="level-end">
<span class="level-item tag">${category.count}</span>
</span>
</a>`;
if (category.hasOwnProperty('children')) {
result += '<ul>' + build_list(category.children) + '</ul>';
}
return result + '</li>';
}).join('');

themes\icarus\_config.yml

1
2
3
4
5
6
7
8
9
10
# 配置各个分类的权重,一级和二级不冲突
categort_weight:
php: 1
laravel: 11
thinkphp: 12
go: 2
javascript: 3
vue: 31
python: 4
其他: 5

测试

排序前

排序后

往上