{{ post.title }}
- {% else %} -{{ post.title }}
-{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
- {% endif %} -diff --git a/_includes/group-by-array.html b/_includes/group-by-array.html new file mode 100644 index 00000000..33af7555 --- /dev/null +++ b/_includes/group-by-array.html @@ -0,0 +1,47 @@ + + + +{% assign __empty_array = '' | split: ',' %} +{% assign group_names = __empty_array %} +{% assign group_items = __empty_array %} + + +{% assign __names = include.collection | map: include.field %} + + +{% assign __names = __names | join: ',' | join: ',' | split: ',' %} + + +{% assign __names = __names | sort %} +{% for name in __names | sort %} + + + {% unless name == previous %} + + + {% assign group_names = group_names | push: name %} + {% endunless %} + + {% assign previous = name %} +{% endfor %} + + + +{% for name in group_names %} + + + {% assign __item = __empty_array %} + {% for __element in include.collection %} + {% if __element[include.field] contains name %} + {% assign __item = __item | push: __element %} + {% endif %} + {% endfor %} + + + {% assign group_items = group_items | push: __item %} +{% endfor %} diff --git a/_pages/category-archive.html b/_pages/category-archive.html index 617eef2c..6e6f5126 100644 --- a/_pages/category-archive.html +++ b/_pages/category-archive.html @@ -4,24 +4,19 @@ permalink: /category-archive/ title: "Posts by Category" --- {% include absolute-url.liquid %} -{% capture site_categories %}{% for category in site.categories %}{{ category | first }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %} -{% assign category_list = site_categories | split:',' | sort %} +{% include group-by-array.html collection=site.posts field='categories' %} -{% for item in (0..site.categories.size) %} - {% unless forloop.last %} - {% capture category_name %}{{ category_list[item] | strip_newlines }}{% endcapture %} -
{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
- {% endif %} -{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
{% endif %} - {% endfor %} - {% endunless %} +{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
+ {% endif %} +{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
- {% endif %} -{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}
+ {% endif %} +