perf: include the latest posts in the "Recently Updated" list (#1456)

Improve the "Recently Updated" list to include the most recent (only one Git commit) posts.

This change has two benefits:

1. The post update list is consistent with the git commit timeline.
2. Avoid users not having a list of updates to show when they first publish a site.
This commit is contained in:
Cotes Chung 2024-01-08 05:13:56 +08:00 committed by GitHub
parent 9882244bd9
commit 82d8f2db98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,16 +1,17 @@
<!-- Get the last 5 posts from lastmod list. --> <!-- Get 5 last posted/updated posts -->
{% assign MAX_SIZE = 5 %} {% assign MAX_SIZE = 5 %}
{% assign all_list = '' | split: '' %} {% assign all_list = '' | split: '' %}
{% for post in site.posts %} {% for post in site.posts %}
{% if post.last_modified_at and post.last_modified_at != post.date %} {% assign datetime = post.last_modified_at | default: post.date %}
{% capture elem %} {% capture elem %}
{{- post.last_modified_at | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}} {{- datetime | date: "%Y%m%d%H%M%S" -}}::{{- forloop.index0 -}}
{% endcapture %} {% endcapture %}
{% assign all_list = all_list | push: elem %} {% assign all_list = all_list | push: elem %}
{% endif %}
{% endfor %} {% endfor %}
{% assign all_list = all_list | sort | reverse %} {% assign all_list = all_list | sort | reverse %}