modified: _posts/2015-11-03-on-pca.md
[GalaxyBlog.git] / _includes / JB / posts_collate
blobf612ade871af7280dfc32727d0f6f4922c792f64
1 {% comment %}<!--
2 Collate_posts helper. Collated posts by year and month.
3 Usage:
4   1) assign the 'posts_collate' variable to a valid array of posts.
5   2) include JB/posts_collate
6   example:
7     {% assign posts_collate = site.posts %}
8     {% include JB/posts_collate %}
10   Ordering:
11     Posts are displayed in reverse chronological order.
12     For normal chronological order:
13       1) Change the for loop to this:
14         => 'for post in site.posts reversed'
15       2) Next make sure to change 'post.previous.date' to:
16         => 'post.next.date'
17         
18 -->{% endcomment %}
20 {% if site.JB.posts_collate.provider == "custom" %}
21   {% include custom/posts_collate %}
22 {% else %}
23   {% for post in posts_collate  %}
24     {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
25     {% capture this_month %}{{ post.date | date: "%B" }}{% endcapture %}
26     {% capture next_year %}{{ post.previous.date | date: "%Y" }}{% endcapture %}
27     {% capture next_month %}{{ post.previous.date | date: "%B" }}{% endcapture %}
28   
29     {% if forloop.first %}
30       <h2>{{this_year}}</h2>
31       <h3>{{this_month}}</h3>
32       <ul>
33     {% endif %}
34   
35     <li><span>{{ post.date | date: "%B %e, %Y" }}</span> &raquo; <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></li>
36   
37     {% if forloop.last %}
38       </ul>
39     {% else %}
40       {% if this_year != next_year %}
41         </ul>
42         <h2>{{next_year}}</h2>
43         <h3>{{next_month}}</h3>
44         <ul>
45       {% else %}    
46         {% if this_month != next_month %}
47           </ul>
48           <h3>{{next_month}}</h3>
49           <ul>
50         {% endif %}
51       {% endif %}
52     {% endif %}
53   {% endfor %}
54 {% endif %}
55 {% assign posts_collate = nil %}