Overview

We can iterate over site.categories, each item is an array with two elements. The first element in the array is the category name, the second element is a list of the posts in that category.

...
{% for category in site.categories %}
  <h2>{{ category[0] }}</h2>
  <ul>
    {% for post in category[1] %}
      <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
  </ul>
{% endfor %}
...