Snippet: sorting on custom date in Jekyll
On my blog I want to tag certain posts as “work” so that I can create a separate page that serves as a portfolio of my work. Because the date of the post isn’t always the date of the work I’ve done, some customisations were needed that were not directly available on the web or the Jekyll documentation.
I’ve added a category and custom date to the post’s front matter:
category: work
work_date: 2015-01-01 # format = YYYY-MM-DD
This gives us the necessary information to create a list of posts and a date to order them by. To solve the sorting issue, I used the following code:
{% assign sorted_posts = (site.categories.work | sort: 'work_date') %}
{% for post in sorted_posts reversed %}
<!-- your post here -->
{% endfor %}
May it serve you well.