How to sort jekyll pagination by date

I don’t have any date frontmatter in my blog post.

The only date is available in my blog post name is 2019-09-16-my-first-blog-post.md

I’m using these code in my index.html(homepage)

{% for post in paginator.posts %}

  <li class="post">
  	<h2><a href="{% if site.baseurl == "/" %}{{ post.url }}{% else %}{{ post.url | prepend: site.baseurl }}{% endif %}">{{ post.title }}</a></h2><br/>
  	<p>{{ post.content }}</p>
  </li>

{% endfor %}

This code doesn’t return latest post by date.

In past when I was not using pagination then I was using this for loop

{% for post in site.posts limit:20 %}

And it returns latest 20 post in my homepage.

I’ve tried to add | sort: 'date' but nothing works on above code.

p.s. I’m using custom permalink in my all blog post, do you think that cause problem? Jekyll state that, but they did not specify it will break the order of post.

1 Like