@@ -119,6 +119,23 @@ const PERIOD = 30;
119
119
120
120
const days = ( from , to = Date . now ( ) ) => ( new Date ( to ) - new Date ( from ) ) / DAY / 1000 ;
121
121
122
+ const months = ( startDate , endDate = new Date ( ) ) => {
123
+ if ( startDate > endDate ) {
124
+ [ startDate , endDate ] = [ endDate , startDate ] ;
125
+ }
126
+
127
+ const startYear = startDate . getFullYear ( ) ;
128
+ const startMonth = startDate . getMonth ( ) ;
129
+
130
+ const endYear = endDate . getFullYear ( ) ;
131
+ const endMonth = endDate . getMonth ( ) ;
132
+
133
+ let months = ( endYear - startYear ) * 12 ;
134
+ months += endMonth - startMonth ;
135
+
136
+ return months ;
137
+ }
138
+
122
139
const readJSON = async ( fileName ) => JSON . parse ( String ( await fs . readFile ( fileName ) ) ) ;
123
140
const writeJSON = async ( fileName , data ) => await fs . writeFile ( fileName , JSON . stringify ( data , null , 2 ) ) ;
124
141
@@ -438,13 +455,13 @@ const processGithub = async (sponsor, repo = 'axios-sponsor', file = 'sponsor.js
438
455
439
456
440
457
const renderTooltip = async ( sponsor ) => {
441
- let { icon, isActive, displayName, tier, tierId, lastTransactionAmount, price , description, website, benefits, video, autoUTMLinks, links} = sponsor ;
458
+ let { icon, isActive, displayName, tier, tierId, lastTransactionAmount, tierPrice , description, website, benefits, video, autoUTMLinks, links} = sponsor ;
442
459
443
460
const iconSrc = icon && ( await downloadImage ( icon ) ) ;
444
461
445
462
const iconHTML = iconSrc ? `<img class="sponsor-icon" src="/${ iconSrc } " alt="${ html . escape ( displayName ) } "/>` : '' ;
446
463
447
- const renderedTier = isActive && ( tierId === 'backer' || sponsor . tierPrice < sponsor . originalTierPrice ) ? `${ price || lastTransactionAmount || 0 } $ a month` : tier ;
464
+ const renderedTier = isActive && ( tierId === 'backer' || sponsor . tierPrice < sponsor . originalTierPrice ) ? `${ tierPrice || lastTransactionAmount || 0 } $ a month` : tier ;
448
465
449
466
let tooltip = `<h2 class="caption">${ iconHTML } <span>${ html . escape ( displayName ) } (${ sponsor . totalAmountDonated || 0 } $${ ' <sup class="tier">' + renderedTier + '</sup>' } )</span></h2> ` ;
450
467
@@ -572,6 +589,13 @@ const processSponsors = async (collectiveSponsors, sponsorsConfig = './data/spon
572
589
573
590
const sponsorTiers = merge ( { } , tiers , sponsor . tiers ) ;
574
591
592
+ if ( sponsor . totalAmountDonated == null && sponsor . isActive ) {
593
+ const passedMonths = sponsor . createdAt ? months ( new Date ( sponsor . createdAt ) ) : null ;
594
+ const tierPrice = sponsor . tier && sponsorTiers [ sponsor . tier ] ?. price ;
595
+
596
+ sponsor . totalAmountDonated = passedMonths != null && tierPrice ? passedMonths * tierPrice : 0 ;
597
+ }
598
+
575
599
if ( lastTransactionAmount ) {
576
600
sponsor . tier = findTier ( lastTransactionAmount , sponsorTiers ) ;
577
601
0 commit comments