Skip to content

Commit be58bcf

Browse files
fix(sponsors): fix custom tiers processing; (#238)
* feat: add sponsor list generator; * feat: added deploy action; * fix: fixed layout; * fix: use utm links inside tooltips; * fix(CI): set engine version; * chore: reverted the start button title change; * fix: add the ability to retry the request to get a list of sponsors; * chore: change sponsors config & fix sponsor card layout; * chore: hide 'incognito' sponsor from the list of sponsors; * chore: add Route4Me sponsor; * chore: fixed resolution of utm link for manually added sponsors; * chore: fixed sponsors' tiers resolving; * chore: draft; * chore(sponsors): disable utm links generation for `slotozilla-deutschland`; * chore(draft): Improve sponsors list generator; * chore(draft): fix origin preset; * chore(draft): delete generated icon; * chore(draft): add check to ensure dir exists; * chore(draft): add check to ensure dir exists; * chore(draft): activate GitHub data pulling; * chore(draft): fix crown chevron styling; * chore(draft): reduce logo min-width; * chore(draft): add missed `route4me` light logo; * chore(draft): add a title for readme sponsor block; * chore(draft): fix description resolving; * chore(draft): add utm links for sponsors rendered to markdown; * chore(draft): respect autoUTMLinks for utm links generation; * chore(draft): set user theme timeout to 24 hours; * chore(draft): set utm link for markdown output; * chore(draft): add sponsors' logos; * chore(draft): fix sponsor.json; * chore(draft): fix sponsor.json; * chore(draft): add principal logo; * chore(draft): add a hotfix for svg logos; * chore(draft): use image metadata instead of file extension to determine image format; * chore(draft): add Stytch & Descope links; * chore(draft): fix utm link generator to respect sponsor's params; * chore(draft): add page active link rendering; * chore(draft): notes block refactoring; * chore(draft): remove graphql packages; * chore(sponsors): add website link for buzzoid.com; * chore(sponsors): remove Route4me from the list; * chore(sponsors): Fixed relative URLs for dark theme logos in the Readme sponsor generator; * fix(sponsors): add a hotfix for sponsors generator by emulating OpenCollective's isActive property. * fix(sponsors): fix custom tiers processing; --------- Co-authored-by: Jay <[email protected]>
1 parent f01fb44 commit be58bcf

File tree

7 files changed

+62
-36
lines changed

7 files changed

+62
-36
lines changed

data/sponsors.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
"scoreTotalAmountFactor": 0.2,
77
"tiers": {
88
"backer" : {
9+
"name": "Backer",
910
"price": 20,
1011
"benefits": {
1112
"showAtSponsorList": true
1213
},
1314
"period": 2
1415
},
1516
"bronze": {
17+
"name": "Bronze",
1618
"price": 49,
1719
"benefits": {
1820
"showAtSponsorList": true
1921
}
2022
},
2123
"silver" : {
24+
"name": "Silver",
2225
"price": 99,
2326
"benefits": {
2427
"showAtSponsorList": true,
@@ -27,6 +30,7 @@
2730
}
2831
},
2932
"gold" : {
33+
"name": "Gold",
3034
"price": 299,
3135
"benefits": {
3236
"showAtSponsorList": true,
@@ -40,6 +44,7 @@
4044
}
4145
},
4246
"platinum" : {
47+
"name": "Platinum",
4348
"price": 599,
4449
"benefits": {
4550
"showAtSponsorList": true,
@@ -92,7 +97,6 @@
9297
"autoUTMLinks": false
9398
},
9499
"stytch": {
95-
"tier": "gold",
96100
"description": "API-first authentication, authorization, and fraud prevention",
97101
"image": "/assets/sponsors/stytch.png",
98102
"image_dark": "/assets/sponsors/stytch_white.png",
@@ -101,22 +105,36 @@
101105
"Website": "https://stytch.com/?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=website-link&utm_campaign=axios-http",
102106
"Documentation": "https://stytch.com/docs?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=docs-link&utm_campaign=axios-http",
103107
"Node.js": "https://github.com/stytchauth/stytch-node?utm_source=oss-sponsorship&utm_medium=paid_sponsorship&utm_content=node-sdk&utm_campaign=axios-http"
108+
},
109+
"tiers": {
110+
"gold": {
111+
"price": 200
112+
}
104113
}
105114
},
106115
"descope": {
107-
"tier": "gold",
108116
"image": "/assets/sponsors/descope.png",
109117
"image_dark": "/assets/sponsors/descope_white.png",
110118
"targetLink": "https://www.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship",
111119
"links": {
112120
"Website": "https://www.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship",
113-
"Documentation": "https://docs.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship",
121+
"Docs": "https://docs.descope.com/?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship",
114122
"Community": "https://www.descope.com/community?utm_source=axios&utm_medium=referral&utm_campaign=axios-oss-sponsorship"
123+
},
124+
"tiers": {
125+
"gold": {
126+
"price": 200
127+
}
115128
}
116129
},
117130
"principal": {
118131
"tier": "gold",
119-
"image": "/assets/sponsors/principal.svg"
132+
"image": "/assets/sponsors/principal.svg",
133+
"tiers": {
134+
"gold": {
135+
"price": 175
136+
}
137+
}
120138
},
121139
"buy-instagram-followers-buzzoid": {
122140
"website": "https://buzzoid.com/buy-instagram-followers/"

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"http-server": "^14.1.0",
2424
"inert-ssg": "^2.0.0-alpha.15",
2525
"joi": "^17.13.3",
26+
"lodash": "^4.17.21",
2627
"mime-types": "^2.1.35",
2728
"sharp": "^0.31.3"
2829
}

scripts/updateData.js

+35-29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const crypto = require('crypto');
88
const Joi = require('joi');
99
const Handlebars = require('handlebars');
1010
const axios = require('axios');
11+
const {merge} = require('lodash');
1112

1213
const origin = 'https://axios-http.com/';
1314
//const origin = 'http://127.0.0.1:8080/';
@@ -436,13 +437,13 @@ const processGithub = async (sponsor, repo = 'axios-sponsor', file = 'sponsor.js
436437

437438

438439
const renderTooltip = async (sponsor) => {
439-
let {icon, isActive, displayName, tier, lastTransactionAmount, price, description, website, benefits, video, autoUTMLinks, links} = sponsor;
440+
let {icon, isActive, displayName, tier, tierId, lastTransactionAmount, price, description, website, benefits, video, autoUTMLinks, links} = sponsor;
440441

441442
const iconSrc = icon && (await downloadImage(icon));
442443

443444
const iconHTML = iconSrc ? `<img class="sponsor-icon" src="/${iconSrc}" alt="${html.escape(displayName)}"/>` : '';
444445

445-
const renderedTier = isActive && tier.toLowerCase() === 'backer' ? `${price || lastTransactionAmount || 0}$ a month` : tier;
446+
const renderedTier = isActive && (tierId === 'backer' || sponsor.tierPrice < sponsor.originalTierPrice) ? `${price || lastTransactionAmount || 0}$ a month` : tier;
446447

447448
let tooltip = `<h2 class="caption">${iconHTML}<span>${html.escape(displayName)} (${sponsor.totalAmountDonated || 0}$${' <sup class="tier">' + renderedTier + '</sup>'})</span></h2> `;
448449

@@ -502,7 +503,7 @@ const findTier = (price, tiers) => {
502503
price && Object.entries(tiers).forEach(([tier, data]) => {
503504
if (data.price <= price && max < price) {
504505
max = data.price;
505-
found = tier;
506+
found = data.name || tier;
506507
}
507508
});
508509

@@ -537,9 +538,15 @@ const processSponsors = async (collectiveSponsors, sponsorsConfig = './data/spon
537538
const {period = 31} = tierData || {};
538539
const isActiveSubscription = tierData && passed <= period;
539540

540-
sponsor.isActive = !!(isActiveSubscription && lastTransactionAmount > 0 && totalAmountDonated);
541+
if (tier) {
542+
sponsor.isActive = !!(isActiveSubscription && lastTransactionAmount > 0 && totalAmountDonated);
543+
} else {
544+
sponsor.isActive = undefined;
545+
}
541546

542-
mergedSponsors[sponsor.login] = {...sponsor};
547+
if (!mergedSponsors[sponsor.login] || sponsor.isActive) {
548+
mergedSponsors[sponsor.login] = {...sponsor};
549+
}
543550
});
544551

545552
// merge sponsors from sponsors.json
@@ -550,7 +557,6 @@ const processSponsors = async (collectiveSponsors, sponsorsConfig = './data/spon
550557
login,
551558
...collective,
552559
...local,
553-
localConfig: {...local},
554560
manualBilling: !!(local.lastTransactionAt && local.lastTransactionAmount || local.endDate)
555561
}
556562
});
@@ -559,39 +565,44 @@ const processSponsors = async (collectiveSponsors, sponsorsConfig = './data/spon
559565

560566
// normalize sponsors config
561567
Object.entries(mergedSponsors).forEach(([login, sponsor]) => {
562-
if (!sponsor.tier) {
563-
sponsor.tier = 'backer';
564-
}
565568

566-
let {isActive, tier, lastTransactionAmount = 0, lastTransactionAt, manualBilling, localConfig} = sponsor;
569+
let {lastTransactionAmount = 0, lastTransactionAt, manualBilling} = sponsor;
570+
571+
const sponsorTiers = merge({}, tiers, sponsor.tiers);
567572

568-
const tierLower = tier.toLowerCase();
573+
if (lastTransactionAmount) {
574+
sponsor.tier = findTier(lastTransactionAmount, sponsorTiers);
575+
}
569576

570-
const tierData = tiers[tierLower];
577+
const tierId = sponsor.tier ? sponsor.tier?.toLowerCase() : null;
578+
const tierData = tierId && sponsorTiers[tierId];
571579

572-
if (!tierData) {
573-
console.log(`Unknown tier [${tier}]`);
580+
if (tierId && !tierData) {
581+
console.log(`Unknown tier [${sponsor.tier}]`);
574582
}
575583

576584
const {price, benefits, period = PERIOD} = tierData || {};
577585

586+
if (sponsor.isActive == null) {
587+
sponsor.isActive = tierData && days(lastTransactionAt) <= period && sponsor.lastTransactionAmount >= price;
588+
}
589+
578590
console.log(sponsor.login);
579591

580-
const isBacker = tierLower === 'backer';
592+
const originalTierPrice = tiers[tierId]?.price;
581593

582-
sponsor.tierId = tierLower;
583-
sponsor.tierPrice = isBacker && isActive && lastTransactionAmount ? lastTransactionAmount : price;
594+
const isCustomTier = !!(tierData && price !== originalTierPrice);
595+
sponsor.tierId = tierId;
596+
sponsor.tier = sponsor.tier + (lastTransactionAmount > originalTierPrice ? '+' : '')
597+
sponsor.tierPrice = price;
598+
sponsor.originalTierPrice = originalTierPrice;
599+
sponsor.isCustomTier = isCustomTier;
584600
sponsor.totalAmountDonated = sponsor.totalAmountDonated || lastTransactionAmount || 0;
585601

586-
sponsor.associatedTierId = tierLower;
587-
588602

589-
let assoc;
590603

591-
if (localConfig?.isActive === false) {
592-
sponsor.isActive = false;
593-
} else if (tier && (manualBilling || tierLower === 'backer')) {
594-
if(sponsor.endDate || lastTransactionAmount >= price) {
604+
if (sponsor.tier && manualBilling) {
605+
if (sponsor.endDate || lastTransactionAmount >= price) {
595606
const pricePerSec = price / (period * DAY);
596607
const timePaid = lastTransactionAmount / pricePerSec
597608
const endDate = sponsor.endDate = sponsor.endDate || +(new Date(lastTransactionAt)) + timePaid * 1000;
@@ -608,11 +619,6 @@ const processSponsors = async (collectiveSponsors, sponsorsConfig = './data/spon
608619
sponsor.boost = sponsor.boost || 1;
609620
}
610621

611-
if (isActive && isBacker && !localConfig?.tier && (assoc = findTier(lastTransactionAmount, tiers))) {
612-
const tier = assoc.toLowerCase();
613-
tier !== 'backer' && (sponsor.associatedTierId = tier);
614-
}
615-
616622
sponsor.isActive = sponsor.isActive === true;
617623

618624
sponsor.benefits = {

templates/home.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<% if (count) { %>
104104
<% config.custom.sponsors && config.custom.sponsors.forEach(sponsor => { %>
105105
<% if(sponsor.isActive && !sponsor.hide && sponsor.benefits.showAtSponsorList ){ %>
106-
<li class="splide__slide sponsor-card <%= sponsor.visual.className || "" %> opacity_<%= Math.round(4 * sponsor.visual.opacity) * 25 %>" data-tier="<%=sponsor.associatedTierId%>" data-is-wide="<%= !!sponsor.isWideImage %>" data-is-active="<%= sponsor.isActive ? "yes" : "no" %>" data-image-type="<%= sponsor.imageType || '' %>" <% if(sponsor.tooltip){ %>data-tippy-content="<%= sponsor.tooltip %>"<% } %>>
106+
<li class="splide__slide sponsor-card <%= sponsor.visual.className || "" %> opacity_<%= Math.round(4 * sponsor.visual.opacity) * 25 %>" data-tier="<%=sponsor.tierId%>" data-is-wide="<%= !!sponsor.isWideImage %>" data-is-active="<%= sponsor.isActive ? "yes" : "no" %>" data-image-type="<%= sponsor.imageType || '' %>" <% if(sponsor.tooltip){ %>data-tippy-content="<%= sponsor.tooltip %>"<% } %>>
107107
<a href="<%= sponsor.targetLink || '#' %>" target="_blank" >
108108
<% if(sponsor.image){ %>
109109
<div>

templates/post.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
<% if (count) { %>
213213
<% config.custom.sponsors && config.custom.sponsors.forEach(sponsor => { %>
214214
<% if(sponsor.isActive && !sponsor.hide && sponsor.benefits.showAtPages ){ %>
215-
<li class="splide__slide sponsor-card <%= sponsor.visual.className || "" %> opacity_<%= Math.round(4 * sponsor.visual.opacity) * 25 %>" data-tier="<%=sponsor.associatedTierId%>" data-is-wide="<%= !!sponsor.isWideImage %>" data-has-logo="<%= !!sponsor.image %>" data-is-active="<%= sponsor.isActive ? "yes" : "no" %>" data-image-type="<%= sponsor.imageType || '' %>" <% if(sponsor.tooltip){ %>data-tippy-content="<%= sponsor.tooltip %>"<% } %>>
215+
<li class="splide__slide sponsor-card <%= sponsor.visual.className || "" %> opacity_<%= Math.round(4 * sponsor.visual.opacity) * 25 %>" data-tier="<%=sponsor.tierId%>" data-is-wide="<%= !!sponsor.isWideImage %>" data-has-logo="<%= !!sponsor.image %>" data-is-active="<%= sponsor.isActive ? "yes" : "no" %>" data-image-type="<%= sponsor.imageType || '' %>" <% if(sponsor.tooltip){ %>data-tippy-content="<%= sponsor.tooltip %>"<% } %>>
216216
<a href="<%= sponsor.targetLink || '#' %>" target="_blank" >
217217
<% if(sponsor.image){ %><div>
218218
<% if (sponsor.tierId=== 'platinum' && sponsor.benefits.crown) { %><div class="chevron"><span class="sponsor_chevron_crown"></span></div><% } %>

templates/sponsors.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{{/if}}
2424
{{#if description}}<p align="center" title="{{description}}">{{#short benefits.maxReadmeDescLength}}{{description}}{{/short}}</p>{{else}}{{#if showCaptions}}<p align="center">{{displayName}}</p>{{/if}}{{/if}}
2525
{{#if links}}<p align="center">
26-
{{#each links}}<a href="{{this}}"><b>{{@key}}</b></a>{{#sep}} | {{/sep}}{{/each}}
26+
{{#each links}}<a href="{{this}}"><b>{{#short 40}}{{@key}}{{/short}}</b></a>{{#sep}} | {{/sep}}{{/each}}
2727
</p>{{/if}}
2828
{{else}}
2929
- {{displayName}}

0 commit comments

Comments
 (0)