What I am trying to do is
- For every item
post
in arraysite.posts
- Assign a custom property
sort_date
with the value of propertylast_modified_at
- If
last_modified_at
does not exist, assign withdate
instead
- Assign a custom property
- Sort all the
post
in arraysite.posts
bysort_date
I wrote the codes below, but it didn’t sort the posts as expected. Can anyone help me with it?
{%-assign posts = site.posts-%}
{%-for post in posts-%}
{%-assign sort_date = last_modified_at | default: date-%}
{%- endfor -%}
{%- assign posts = posts | sort: "sort_date" -%}
<ul>
{%- for post in posts-%}
<li><a href="{{ post.url | relative_url }}">{{ post.title }}</a></li>
{%- endfor -%}
</ul>