Skip to content

Commit

Permalink
Add thousands separator filter
Browse files Browse the repository at this point in the history
  • Loading branch information
helenclx committed Sep 5, 2024
1 parent 0d06c6a commit cb88d32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/_config/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default function(eleventyConfig) {
return array.slice(0, limit);
});

// Thousands separator
eleventyConfig.addFilter("thousands", function(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});

// Filter blog posts by category
eleventyConfig.addFilter("filterByCategory", function(posts, cat) {
cat = cat.toLowerCase();
Expand Down
2 changes: 1 addition & 1 deletion src/_includes/global/content.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ layout: global/base
<div class="blog__post--info">
<p>{{ desc }}</p>
<p>
<span class="text-bold">{{ content | wordcount }} words</span>.
<span class="text-bold">{{ content | wordcount | thousands }} words</span>.
<span class="text-bold">Posted:</span> {{ date | niceDate }} by {{ sitemeta.siteAuthor.name }}
</p>
{% if updated %}
Expand Down

0 comments on commit cb88d32

Please sign in to comment.