Skip to content

Commit

Permalink
add filter to show full date
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnthompson committed Sep 16, 2024
1 parent 28972dd commit 9020c45
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,22 @@ module.exports = function (eleventyConfig) {
return collection.filter((item) => item.data.locale === locale);
});

// Specific postDate filter for blog posts or other content with strict formatting
eleventyConfig.addFilter("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" })
.setLocale("en")
.toFormat("yyyy'-'MM'-'dd");
});

// Format date filter to display full date
eleventyConfig.addFilter("formatDate", function (dateObj) {
const locale = this.ctx.locale || 'en'; // Use the locale from the context, default to 'en'

return DateTime.fromJSDate(dateObj, { zone: "utc" })
.setLocale(locale)
.toLocaleString(DateTime.DATE_MED); // Use DATE_MED to exclude the day of the week
});

eleventyConfig.addPassthroughCopy({ "./src/_docs": "docs" });
eleventyConfig.addPassthroughCopy({ "./src/_images": "img" });
eleventyConfig.addPassthroughCopy({ "./src/CNAME": "CNAME" });
Expand Down

0 comments on commit 9020c45

Please sign in to comment.