Public Access
1
0

fix: luxon plugin

This commit is contained in:
2025-08-26 18:29:57 -04:00
parent 67290994a0
commit b2f55c1b10
3 changed files with 19 additions and 19 deletions

View File

@@ -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) { 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 // Pass through static assets from the "src" directory
eleventyConfig.addPassthroughCopy("src/css"); eleventyConfig.addPassthroughCopy("src/css");
@@ -13,25 +15,21 @@ module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(syntaxHighlight); eleventyConfig.addPlugin(syntaxHighlight);
// Add a filter for readable dates using vanilla JS // Add a filter for readable dates using Luxon
eleventyConfig.addFilter("readableDate", dateObj => { eleventyConfig.addFilter("readableDate", (dateObj) => {
// The toLocaleDateString method can be used to format dates if (!dateObj) return "";
// without any external libraries. // When Eleventy parses a date like "2025-08-25", it creates a Date object
// The 'UTC' timeZone option is added to prevent off-by-one day errors. // at midnight UTC. Using Luxon to format this date while treating it as UTC
return new Date(dateObj).toLocaleDateString('en-US', { // prevents the date from shifting to the previous day due to timezone conversion.
year: 'numeric', return DateTime.fromJSDate(dateObj, { zone: 'UTC' }).toFormat('LLLL d, yyyy');
month: 'long',
day: 'numeric',
timeZone: 'UTC'
});
}); });
// Add htmlDateString filter for sitemap <lastmod> // Add htmlDateString filter for sitemap <lastmod>
eleventyConfig.addFilter("htmlDateString", dateObj => { eleventyConfig.addFilter("htmlDateString", (dateObj) => {
if (!dateObj) return ""; if (!dateObj) return "";
// Format date as YYYY-MM-DD for sitemaps // toISODate() will return the date in YYYY-MM-DD format.
const d = new Date(dateObj); // We specify UTC zone to ensure the date is not affected by the system's timezone.
return d.toISOString().split("T")[0]; return DateTime.fromJSDate(dateObj, { zone: 'UTC' }).toISODate();
}); });
// Shortcode for creating a callout box // Shortcode for creating a callout box

3
package-lock.json generated
View File

@@ -13,7 +13,8 @@
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2", "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.21.2", "express": "^4.21.2",
"fs-extra": "^11.3.1" "fs-extra": "^11.3.1",
"luxon": "^3.7.1"
}, },
"devDependencies": { "devDependencies": {
"http-proxy-middleware": "^3.0.0", "http-proxy-middleware": "^3.0.0",

View File

@@ -15,7 +15,8 @@
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2", "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.21.2", "express": "^4.21.2",
"fs-extra": "^11.3.1" "fs-extra": "^11.3.1",
"luxon": "^3.7.1"
}, },
"devDependencies": { "devDependencies": {
"http-proxy-middleware": "^3.0.0", "http-proxy-middleware": "^3.0.0",