Hi –
I used a different approach, and tried to help myself 🙂
I followed the instructions this page: https://getpublii.com/dev/yearly-archive-for-posts/ and changed createdAt to modifiedAt.
Working this way gives me a list of all modified posts for 2023, for example.
What I still need
- is a hint on how to limit the list to 5,
- and on how to order the list in a timely manner…
Cheers, Michael
The screenshot shows the result I get by now
A) the .hbs part:
{{#each (yearsInArchive 2023)}}
{{#if (getPostsByYear @website.contentStructure.posts this)}}
{{#each (getPostsByYear @website.contentStructure.posts this)}}
- {{date modifiedAt "YYYY-MM-DD"}}
{{/each}}
{{/if}}
{{/each}}
B) and the helpers script:
let themeHelpers = {
yearsInArchive: function (startYear) {
let years = [];
let currentYear = new Date().getFullYear();
for (let i = currentYear; i >= startYear; i--) {
years.push(i);
}
return years;
},
getPostsByYear: function (posts, year) {
return posts.filter(post => new Date(post.modifiedAt).getFullYear() === year);
}
};
module.exports = themeHelpers;