diff --git a/eleventy.config.js b/eleventy.config.js index a19f710..ab1aec1 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -20,6 +20,8 @@ const figoptions = { figcaption: true, }; +const timeZone = "America/Chicago"; + export default async function (eleventyConfig) { // Helper Functions const multiReplace = (text, replacementTable) => { @@ -30,6 +32,25 @@ export default async function (eleventyConfig) { return newText; }; + eleventyConfig.addDateParsing((dateValue) => { + let localDate; + if (dateValue instanceof Date) { + // and YAML + localDate = DateTime.fromJSDate(dateValue, { zone: "utc" }).setZone( + timeZone, + { keepLocalTime: true }, + ); + } else if (typeof dateValue === "string") { + localDate = DateTime.fromISO(dateValue, { zone: timeZone }); + } + if (localDate?.isValid === false) { + throw new Error( + `Invalid \`date\` value (${dateValue}) is invalid for ${this.page.inputPath}: ${localDate.invalidReason}`, + ); + } + return localDate; + }); + // Collections eleventyConfig.addCollection("galleryImages", (collection) => { const galleries = collection.getAll()[0].data.galleries; @@ -84,7 +105,6 @@ export default async function (eleventyConfig) { }); eleventyConfig.addFilter("htmlDateString", (dateObj) => { - // dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd"); });