Add support for formatting ISO dates

This commit is contained in:
Leilukin 2024-08-11 21:25:16 +08:00 committed by Helen Chong
parent 74ca916b59
commit 9f93cf1d04

View File

@ -12,8 +12,12 @@ export default function(eleventyConfig) {
});
// Format dates
eleventyConfig.addFilter("formatDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toFormat("d LLLL yyyy");
eleventyConfig.addFilter("formatDate", (date) => {
const dateFormat = "d LLLL yyyy";
if (typeof date === "object") {
return DateTime.fromJSDate(date).toFormat(dateFormat);
}
return DateTime.fromISO(date, { setZone: true }).toFormat(dateFormat);
});
// Limit number of items displayed