From 2b02329cd25763ecfb052facf1804f879ec10315 Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Thu, 5 Sep 2024 23:51:55 +0800 Subject: [PATCH] Add thousands separator filter --- src/_config/filters.js | 5 +++++ src/_includes/global/content.njk | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/_config/filters.js b/src/_config/filters.js index b44a21a7..fa0371a7 100644 --- a/src/_config/filters.js +++ b/src/_config/filters.js @@ -24,4 +24,9 @@ export default function(eleventyConfig) { eleventyConfig.addFilter("itemLimit", function(array, itemLimit) { return array.slice(0, itemLimit); }); + + // Thousands separator + eleventyConfig.addFilter("thousands", function(num) { + return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); + }); } \ No newline at end of file diff --git a/src/_includes/global/content.njk b/src/_includes/global/content.njk index 4f686713..49236f07 100644 --- a/src/_includes/global/content.njk +++ b/src/_includes/global/content.njk @@ -18,7 +18,7 @@ {% if isArticle %}

{{ desc }}

-

{{ content | wordcount }} words. Posted on {{ date | formatDate }} by {{ sitemeta.siteAuthor.name }}

+

{{ content | wordcount | thousands }} words. Posted on {{ date | formatDate }} by {{ sitemeta.siteAuthor.name }}

{% if updated %}

Last updated on {{ updated | formatDate }}

{% endif %}