Skip to content

Commit 9020c45

Browse files
committed
add filter to show full date
1 parent 28972dd commit 9020c45

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

.eleventy.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,22 @@ module.exports = function (eleventyConfig) {
109109
return collection.filter((item) => item.data.locale === locale);
110110
});
111111

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

119+
// Format date filter to display full date
120+
eleventyConfig.addFilter("formatDate", function (dateObj) {
121+
const locale = this.ctx.locale || 'en'; // Use the locale from the context, default to 'en'
122+
123+
return DateTime.fromJSDate(dateObj, { zone: "utc" })
124+
.setLocale(locale)
125+
.toLocaleString(DateTime.DATE_MED); // Use DATE_MED to exclude the day of the week
126+
});
127+
118128
eleventyConfig.addPassthroughCopy({ "./src/_docs": "docs" });
119129
eleventyConfig.addPassthroughCopy({ "./src/_images": "img" });
120130
eleventyConfig.addPassthroughCopy({ "./src/CNAME": "CNAME" });

0 commit comments

Comments
 (0)