Add support for formatting ISO dates

This commit is contained in:
Helen Chong 2024-08-11 21:25:16 +08:00
parent 18d99cfe6c
commit d48a11c9a2
1 changed files with 6 additions and 2 deletions

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