Use luxon to format dates

This commit is contained in:
Helen Chong 2024-08-11 20:21:32 +08:00
parent ad0573915e
commit 18d99cfe6c
1 changed files with 4 additions and 8 deletions

View File

@ -1,3 +1,5 @@
import { DateTime } from "luxon";
export default function(eleventyConfig) { export default function(eleventyConfig) {
// Filter contents by category // Filter contents by category
eleventyConfig.addFilter("filterByCategory", function(contents, cat) { eleventyConfig.addFilter("filterByCategory", function(contents, cat) {
@ -10,14 +12,8 @@ export default function(eleventyConfig) {
}); });
// Format dates // Format dates
const dateOptions = { eleventyConfig.addFilter("formatDate", (dateObj) => {
year: 'numeric', return DateTime.fromJSDate(dateObj).toFormat("d LLLL yyyy");
month: 'long',
day: 'numeric',
};
const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions);
eleventyConfig.addFilter("formatDate", function(date) {
return dateTimeLocale.format(date);
}); });
// Limit number of items displayed // Limit number of items displayed