-
Notifications
You must be signed in to change notification settings - Fork 0
/
archives.html
39 lines (36 loc) · 1.13 KB
/
archives.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
---
layout: default
permalink: /archives.html
title: 归档
author: thewangcj
---
<!-- counts 是一个数组里面存放着每年的文章数 -->
{% assign count = 1 %}
{% for post in site.posts reversed %}
{% assign year = post.date | date: '%Y' %}
{% assign nyear = post.next.date | date: '%Y' %}
{% if year != nyear %}
{% assign count = count | append: ', ' %}
{% assign counts = counts | append: count %}
{% assign count = 1 %}
{% else %}
{% assign count = count | plus: 1 %}
{% endif %}
{% endfor %}
<!-- 将 counts 逆序 -->
{% assign counts = counts | split: ', ' | reverse %}
{% assign i = 0 %}
{% for post in site.posts %}
{% assign year = post.date | date: '%Y' %}
{% assign nyear = post.next.date | date: '%Y' %}
<!-- 本篇文章和下一篇文章年份不一样,显示年份及该年文章的数量 -->
{% if year != nyear %}
<h4>
{{ post.date | date: '%Y' }} ({{ counts[i] }})
</h4>
{% assign i = i | plus: 1 %}
{% endif %}
<div>
* {{ post.date | date: '%m-%d' }} <a href="{{ post.url }}">{{ post.title }}</a>
</div>
{% endfor %}