@@ -15,33 +15,29 @@ export default function (eleventyConfig) {
1515 // Collections
1616 eleventyConfig . addCollection ( 'tagsList' , collectionApi => {
1717 const knownTags = new Set ( tags ) ;
18- const tagMap = collectionApi . getAll ( )
18+ const foundTags = collectionApi . getAll ( )
1919 . flatMap ( item => item . data . tags || [ ] )
2020 . reduce ( ( acc , tag ) => {
21- if ( ! acc . has ( tag ) ) {
22- acc . set ( tag , { name : tag , count : 0 } ) ;
23- }
24- acc . get ( tag ) . count += 1 ;
21+ acc . add ( tag ) ;
2522 return acc ;
26- } , new Map ( ) ) ;
27- tagMap . delete ( 'articles' ) ; // all items have this tag
23+ } , new Set ( ) ) ;
24+ foundTags . delete ( 'articles' ) ; // all items have this tag
2825
2926 // check that we know all tags and all known tags are actually used
30- const foundTags = new Set ( tagMap . keys ( ) ) ;
3127 if ( ! setEquals ( knownTags , foundTags ) ) {
3228 const tagsToAdd = foundTags . difference ( knownTags ) ;
3329 const tagsToRemove = knownTags . difference ( foundTags ) ;
3430 throw new Error ( `Update list of tags! Add: ${ [ ...tagsToAdd ] } Remove: ${ [ ...tagsToRemove ] } ` ) ;
3531 }
3632
37- // return values only, sorted by name
38- return [ ...tagMap . values ( ) ] . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
33+ return [ ...foundTags ] . sort ( ) ;
3934 } ) ;
4035
4136 // add templates for all tags
4237 tags . forEach ( tag => {
43- eleventyConfig . addTemplate ( `tags/${ slugify ( tag ) } .njk` , `<p>All articles with the tag <em>${ tag } </em></p>` , {
38+ eleventyConfig . addTemplate ( `tags/${ slugify ( tag ) } .njk` , `<p>All articles with the tag <em>{{ tag }} </em> ({{ collections[tag].length }}) </p>` , {
4439 layout : 'paged.njk' ,
40+ tag,
4541 title : tag ,
4642 pagination : {
4743 data : `collections.${ tag } ` ,
0 commit comments