File tree 1 file changed +22
-14
lines changed
1 file changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,20 @@ const getStyles = ({
187
187
` ;
188
188
} ;
189
189
190
+ /**
191
+ * Return the label for commits according to the selected options
192
+ *
193
+ * @param {boolean } include_all_commits Option to include all years
194
+ * @param {number|undefined } commits_year Option to include only selected year
195
+ * @returns {string } The label corresponding to the options.
196
+ */
197
+ const getTotalCommitsYearLabel = ( include_all_commits , commits_year ) =>
198
+ include_all_commits
199
+ ? ""
200
+ : commits_year
201
+ ? ` (${ commits_year } )`
202
+ : ` (last year)` ;
203
+
190
204
/**
191
205
* @typedef {import('../fetchers/types').StatsData } StatsData
192
206
* @typedef {import('./types').StatCardOptions } StatCardOptions
@@ -274,13 +288,10 @@ const renderStatsCard = (stats, options = {}) => {
274
288
} ;
275
289
STATS . commits = {
276
290
icon : icons . commits ,
277
- label : `${ i18n . t ( "statcard.commits" ) } ${
278
- include_all_commits
279
- ? ""
280
- : commits_year
281
- ? ` (${ commits_year } )`
282
- : ` (last year)`
283
- } `,
291
+ label : `${ i18n . t ( "statcard.commits" ) } ${ getTotalCommitsYearLabel (
292
+ include_all_commits ,
293
+ commits_year ,
294
+ ) } `,
284
295
value : totalCommits ,
285
296
id : "commits" ,
286
297
} ;
@@ -521,13 +532,10 @@ const renderStatsCard = (stats, options = {}) => {
521
532
. filter ( ( key ) => ! hide . includes ( key ) )
522
533
. map ( ( key ) => {
523
534
if ( key === "commits" ) {
524
- return `${ i18n . t ( "statcard.commits" ) } ${
525
- include_all_commits
526
- ? ""
527
- : commits_year
528
- ? ` (${ commits_year } )`
529
- : ` (last year)`
530
- } : ${ totalStars } `;
535
+ return `${ i18n . t ( "statcard.commits" ) } ${ getTotalCommitsYearLabel (
536
+ include_all_commits ,
537
+ commits_year ,
538
+ ) } : ${ totalStars } `;
531
539
}
532
540
return `${ STATS [ key ] . label } : ${ STATS [ key ] . value } ` ;
533
541
} )
You can’t perform that action at this time.
0 commit comments