From b2f55c1b10c018c0ee16d7153f52a242f83c6599 Mon Sep 17 00:00:00 2001 From: giteaadmin Date: Tue, 26 Aug 2025 18:29:57 -0400 Subject: [PATCH] fix: luxon plugin --- .eleventy.js | 32 +++++++++++++++----------------- package-lock.json | 3 ++- package.json | 3 ++- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 89ff8ed..f78bd24 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,6 +1,8 @@ +const { createProxyMiddleware } = require('http-proxy-middleware'); +const { DateTime } = require("luxon"); +const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); + module.exports = function(eleventyConfig) { - const { createProxyMiddleware } = require('http-proxy-middleware'); - const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); // Pass through static assets from the "src" directory eleventyConfig.addPassthroughCopy("src/css"); @@ -13,25 +15,21 @@ module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(syntaxHighlight); - // Add a filter for readable dates using vanilla JS - eleventyConfig.addFilter("readableDate", dateObj => { - // The toLocaleDateString method can be used to format dates - // without any external libraries. - // The 'UTC' timeZone option is added to prevent off-by-one day errors. - return new Date(dateObj).toLocaleDateString('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - timeZone: 'UTC' - }); + // Add a filter for readable dates using Luxon + eleventyConfig.addFilter("readableDate", (dateObj) => { + if (!dateObj) return ""; + // When Eleventy parses a date like "2025-08-25", it creates a Date object + // at midnight UTC. Using Luxon to format this date while treating it as UTC + // prevents the date from shifting to the previous day due to timezone conversion. + return DateTime.fromJSDate(dateObj, { zone: 'UTC' }).toFormat('LLLL d, yyyy'); }); // Add htmlDateString filter for sitemap - eleventyConfig.addFilter("htmlDateString", dateObj => { + eleventyConfig.addFilter("htmlDateString", (dateObj) => { if (!dateObj) return ""; - // Format date as YYYY-MM-DD for sitemaps - const d = new Date(dateObj); - return d.toISOString().split("T")[0]; + // toISODate() will return the date in YYYY-MM-DD format. + // We specify UTC zone to ensure the date is not affected by the system's timezone. + return DateTime.fromJSDate(dateObj, { zone: 'UTC' }).toISODate(); }); // Shortcode for creating a callout box diff --git a/package-lock.json b/package-lock.json index a03e47d..930f512 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2", "cors": "^2.8.5", "express": "^4.21.2", - "fs-extra": "^11.3.1" + "fs-extra": "^11.3.1", + "luxon": "^3.7.1" }, "devDependencies": { "http-proxy-middleware": "^3.0.0", diff --git a/package.json b/package.json index 7154c9c..a916a30 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2", "cors": "^2.8.5", "express": "^4.21.2", - "fs-extra": "^11.3.1" + "fs-extra": "^11.3.1", + "luxon": "^3.7.1" }, "devDependencies": { "http-proxy-middleware": "^3.0.0",