File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ function tagcloudHelper(tags, options) {
19
19
const unit = options . unit || 'px' ;
20
20
const color = options . color ;
21
21
const className = options . class ;
22
+ const showCount = options . show_count ;
23
+ const countClassName = options . count_class || 'count' ;
22
24
const level = options . level || 10 ;
23
25
const { transform } = options ;
24
26
const separator = options . separator || ' ' ;
@@ -68,7 +70,7 @@ function tagcloudHelper(tags, options) {
68
70
}
69
71
70
72
result . push (
71
- `<a href="${ url_for . call ( this , tag . path ) } " style="${ style } "${ attr } >${ transform ? transform ( tag . name ) : tag . name } </a>`
73
+ `<a href="${ url_for . call ( this , tag . path ) } " style="${ style } "${ attr } >${ transform ? transform ( tag . name ) : tag . name } ${ showCount ? `<span class=" ${ countClassName } "> ${ tag . length } </span>` : '' } </a>`
72
74
) ;
73
75
} ) ;
74
76
Original file line number Diff line number Diff line change @@ -290,4 +290,26 @@ describe('tagcloud', () => {
290
290
'<a href="/tags/def/" style="font-size: 10px;" class="tag-cloud-0">def</a>'
291
291
] . join ( ' ' ) ) ;
292
292
} ) ;
293
+
294
+ it ( 'show_count' , ( ) => {
295
+ const result = tagcloud ( { show_count : true } ) ;
296
+
297
+ result . should . eql ( [
298
+ '<a href="/tags/abc/" style="font-size: 13.33px;">abc<span class="count">2</span></a>' ,
299
+ '<a href="/tags/bcd/" style="font-size: 20px;">bcd<span class="count">4</span></a>' ,
300
+ '<a href="/tags/cde/" style="font-size: 16.67px;">cde<span class="count">3</span></a>' ,
301
+ '<a href="/tags/def/" style="font-size: 10px;">def<span class="count">1</span></a>'
302
+ ] . join ( ' ' ) ) ;
303
+ } ) ;
304
+
305
+ it ( 'show_count with custom class' , ( ) => {
306
+ const result = tagcloud ( { show_count : true , count_class : 'tag-count' } ) ;
307
+
308
+ result . should . eql ( [
309
+ '<a href="/tags/abc/" style="font-size: 13.33px;">abc<span class="tag-count">2</span></a>' ,
310
+ '<a href="/tags/bcd/" style="font-size: 20px;">bcd<span class="tag-count">4</span></a>' ,
311
+ '<a href="/tags/cde/" style="font-size: 16.67px;">cde<span class="tag-count">3</span></a>' ,
312
+ '<a href="/tags/def/" style="font-size: 10px;">def<span class="tag-count">1</span></a>'
313
+ ] . join ( ' ' ) ) ;
314
+ } ) ;
293
315
} ) ;
You can’t perform that action at this time.
0 commit comments