Add thousands separator filter

This commit is contained in:
Helen Chong 2024-09-05 23:51:55 +08:00
parent c179700a08
commit 2b02329cd2
2 changed files with 6 additions and 1 deletions

View File

@ -24,4 +24,9 @@ export default function(eleventyConfig) {
eleventyConfig.addFilter("itemLimit", function(array, itemLimit) { eleventyConfig.addFilter("itemLimit", function(array, itemLimit) {
return array.slice(0, itemLimit); return array.slice(0, itemLimit);
}); });
// Thousands separator
eleventyConfig.addFilter("thousands", function(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
} }

View File

@ -18,7 +18,7 @@
{% if isArticle %} {% if isArticle %}
<div class="article__info"> <div class="article__info">
<p class="article__info--desc">{{ desc }}</p> <p class="article__info--desc">{{ desc }}</p>
<p>{{ content | wordcount }} words. Posted on {{ date | formatDate }} by {{ sitemeta.siteAuthor.name }}</p> <p>{{ content | wordcount | thousands }} words. Posted on {{ date | formatDate }} by {{ sitemeta.siteAuthor.name }}</p>
{% if updated %} {% if updated %}
<p>Last updated on {{ updated | formatDate }}</p> <p>Last updated on {{ updated | formatDate }}</p>
{% endif %} {% endif %}