posts_collate 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 %}
  9. Ordering:
  10. Posts are displayed in reverse chronological order.
  11. For normal chronological order:
  12. 1) Change the for loop to this:
  13. => 'for post in site.posts reversed'
  14. 2) Next make sure to change 'post.previous.date' to:
  15. => 'post.next.date'
  16. -->{% endcomment %}
  17. {% if site.JB.posts_collate.provider == "custom" %}
  18. {% include custom/posts_collate %}
  19. {% else %}
  20. {% for post in posts_collate %}
  21. {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
  22. {% capture this_month %}{{ post.date | date: "%B" }}{% endcapture %}
  23. {% capture next_year %}{{ post.previous.date | date: "%Y" }}{% endcapture %}
  24. {% capture next_month %}{{ post.previous.date | date: "%B" }}{% endcapture %}
  25. {% if forloop.first %}
  26. <h2>{{this_year}}</h2>
  27. <h3>{{this_month}}</h3>
  28. <ul>
  29. {% endif %}
  30. <li><span>{{ post.date | date: "%B %e, %Y" }}</span> &raquo; <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></li>
  31. {% if forloop.last %}
  32. </ul>
  33. {% else %}
  34. {% if this_year != next_year %}
  35. </ul>
  36. <h2>{{next_year}}</h2>
  37. <h3>{{next_month}}</h3>
  38. <ul>
  39. {% else %}
  40. {% if this_month != next_month %}
  41. </ul>
  42. <h3>{{next_month}}</h3>
  43. <ul>
  44. {% endif %}
  45. {% endif %}
  46. {% endif %}
  47. {% endfor %}
  48. {% endif %}
  49. {% assign posts_collate = nil %}