Breaking Jekyll posts into years

I struggled with this for sometime until I stubmled upon a Stackoverflow post that has what I was looking for.

Seriously people think developers just type all day, I have learnt that one of the biggest skills is knowing how to google your problem and finding the correct soultion. Even the most seasoned developer has to look something up in the docs or on forums now and then. Although developers are mega clever they're not superman.

Breaking up my posts into years.

This is how I did it. If you're using Bootstrap and like the layout I have you can just copy and paste the code block.

{% raw %}
{% for post in site.posts  %}
{% capture this_year %}{{ | date: "%Y" }}{% endcapture %}
{% capture next_year %}{{ | date: "%Y" }}{% endcapture %}

{% if forloop.first %}
<h2 id="{{ this_year }}-ref">{{this_year}}</h2>
<ul class="p-0">
    {% endif %}

    <li style="list-style: none;">
        <div class="row">
            <div class="col-md-8 post_entry my-1">
                <a href="{{ post.url }}">
                    <h2 class="string">{{ post.title }}</h2>
            <div class="col my-1">
                <p class="comment text-small text-right">{{ | date: "%B %e" }}

    {% if forloop.last %}
</ul classp-0>
{% else %}
{% if this_year != next_year %}
<h2 id="{{ next_year }}-ref">{{next_year}}</h2>
<ul class="p-0">
    {% endif %}
    {% endif %}
    {% endfor %}
{% endraw %}

With thanks to the Stackoverflow answer I can now break everything into years, you can too.

2022 No rights reserved.
3D Heart