On the frontpage of my site, I display the newest few posts:
{% for post in posts limit: 6 %}
...
{% endfor %}
This works fine.
Recently I've been going back and editing some old posts, and I want them to show in this list on the frontpage.
I don't want to change their date. Instead, I've been adding a new lastUpdated variable to each post as I edit it, with the date I edited it.
layout: example
lastUpdated: 2020-09-07
---
So now I want to modify the code on my frontpage so that it sorts by lastUpdated if a post has it, and otherwise it should sort by date.
I tried this:
{% assign posts = site.posts
| reverse
| sort: "lastUpdated"
| reverse %}
{% for post in posts limit: 6 %}
...
{% endfor %}
I thought that worked, but it turns out that it's sorting all of the edited posts (the posts that contain lastEdited variables) to the front, followed by newly created posts. I want the edited posts and the newly created posts to both show up in this list, based on their "modified" date.
I tried this:
{% assign posts = site.posts
| sort: "lastUpdated or date" %}
{% for post in posts limit: 6 %}
...
{% endfor %}
But that gives me the posts in the default order, presumably because "lastUpdated or date" is not a valid property.
I also tried this:
{% assign posts = site.posts
| sort: "lastUpdated" or "date" %}
{% for post in posts limit: 6 %}
...
{% endfor %}
But not surprisingly, this is a syntax error.
Is there a simple way to do this that I'm missing?