Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll: How to change the default ordering of collections

Tags:

jekyll

I have a collection in my jekyll site that has files named as numbers. 1, 2, 3, ... 10, 11, 12, and so on. I'm building these pages to connect with each other, so 1 would connect to 2, ...

When I build, jekyll serves it in the order of 1, 10, 11, 12, 2, 3, ...

How can I have it build in proper numerical order?

like image 705
Kevin Falting Avatar asked Mar 11 '23 10:03

Kevin Falting


1 Answers

After a little more searching, I found this answered question: How to change the default order pages in jekyll

Basically, what I came up with was:

{% assign ordered_pages = site.pages | sort:"title" %}
{% for page in ordered_pages %}

<a href="{{ page.url | relative_url }}">{{ page.title }}</a>

{% endfor %}

Which is nearly identical to the original answer.

like image 162
Kevin Falting Avatar answered May 03 '23 14:05

Kevin Falting