Use luxon to format dates
This commit is contained in:
parent
ad0573915e
commit
18d99cfe6c
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue