add custom date filter

This commit is contained in:
yuki 2025-10-18 07:48:51 -03:00
parent 31dc4a5fbe
commit 32b43663f7
Signed by: yuki
GPG key ID: 0C98E6FF04EC3915
4 changed files with 10 additions and 4 deletions

View file

@ -43,7 +43,7 @@ dont_show_lang_in_footer: true
<h2>{{ "recent-posts" | i18n }}</h2>
<ul>
{% for post in collections.posts | i18n_filter(5) %}
<li><p><a href="{{ post.url }}">{{ post.data.title }}</a><br><span class="date"> {{ post.date.toLocaleString("en-GB", {year: 'numeric', month: '2-digit', day: '2-digit'}) }}</span></p></li>
<li><p><a href="{{ post.url }}">{{ post.data.title }}</a><br><span class="date"> {{ post.date | date("dd/MM/yyyy") }}</span></p></li>
{% endfor %}
</ul>
</div>

View file

@ -1,6 +1,6 @@
const {
I18nPlugin
} = require("@11ty/eleventy");
const { I18nPlugin } = require("@11ty/eleventy");
const { DateTime } = require("luxon");
const i18n = require("eleventy-plugin-i18n");
const eleventySass = require("eleventy-sass");
const toml = require("@iarna/toml");
@ -35,6 +35,10 @@ module.exports = function (eleventyConfig) {
return filtered;
});
eleventyConfig.addFilter("date", function (dateObj, format) {
return DateTime.fromJSDate(dateObj).toFormat(format);
});
eleventyConfig.addPlugin(eleventySass);
eleventyConfig.addPlugin(I18nPlugin, {
defaultLanguage: defaultLanguage,

1
package-lock.json generated
View file

@ -13,6 +13,7 @@
"@iarna/toml": "^2.2.5",
"eleventy-plugin-i18n": "^0.1.3",
"eleventy-sass": "^3.0.0-beta.0",
"luxon": "^3.7.2",
"markdown-it-emoji": "^3.0.0",
"markdown-it-emoji-customizer": "github:actuallysomecat/markdown-it-emoji-customizer",
"sass": "^1.86.0"

View file

@ -17,6 +17,7 @@
"@iarna/toml": "^2.2.5",
"eleventy-plugin-i18n": "^0.1.3",
"eleventy-sass": "^3.0.0-beta.0",
"luxon": "^3.7.2",
"markdown-it-emoji": "^3.0.0",
"markdown-it-emoji-customizer": "github:actuallysomecat/markdown-it-emoji-customizer",
"sass": "^1.86.0"