From 25b8fe4f50dcf4593118cd2073c2de28281995db Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Sat, 13 Apr 2024 15:07:07 +0800 Subject: [PATCH] Add filters to format dates and limit items --- eleventy.config.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/eleventy.config.js b/eleventy.config.js index cbea2682..2cd43479 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -19,6 +19,23 @@ module.exports = function (eleventyConfig) { eleventyConfig.addWatchTarget("./src/assets/"); eleventyConfig.addPassthroughCopy({ "./src/assets/feed/": "/" }); + // Filter: Format dates + const dateOptions = { + weekday: 'long', + year: 'numeric', + month: 'long', + day: 'numeric', + }; + const dateTimeLocale = new Intl.DateTimeFormat("en-GB", dateOptions); + eleventyConfig.addFilter("niceDate", function(date) { + return dateTimeLocale.format(date); + }); + + // Filter: Limit + eleventyConfig.addFilter("limit", function(array, limit) { + return array.slice(0, limit); + }); + // Installed Plug-ins eleventyConfig.addPlugin(EleventyRenderPlugin); eleventyConfig.addPlugin(pluginWebc, {