@@ -2,114 +2,30 @@ import type { Sponsor } from "@/lib/types";
22
33export const SPECIAL_SPONSOR_THRESHOLD = 100 ;
44
5- export const getSponsorAmount = ( sponsor : Sponsor ) : number => {
6- // If totalProcessedAmount exists, use it, otherwise parse from tierName
7- if ( sponsor . totalProcessedAmount !== undefined ) {
8- return sponsor . totalProcessedAmount ;
9- }
10-
11- // Parse amount from tierName as fallback
12- const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
13- return match ? Number . parseFloat ( match [ 1 ] ) : 0 ;
14- } ;
15-
165export const calculateLifetimeContribution = ( sponsor : Sponsor ) : number => {
17- // If totalProcessedAmount exists, use it, otherwise parse from tierName
18- if ( sponsor . totalProcessedAmount !== undefined ) {
19- return sponsor . totalProcessedAmount ;
20- }
21-
22- // Parse amount from tierName as fallback
23- const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
24- return match ? Number . parseFloat ( match [ 1 ] ) : 0 ;
6+ // totalProcessedAmount is always provided by the API
7+ return sponsor . totalProcessedAmount || 0 ;
258} ;
269
2710export const shouldShowLifetimeTotal = ( sponsor : Sponsor ) : boolean => {
28- // Only show lifetime total if totalProcessedAmount exists
29- return sponsor . totalProcessedAmount !== undefined ;
30- } ;
31-
32- export const filterVisibleSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
33- return sponsors . filter ( ( sponsor ) => {
34- const amount = getSponsorAmount ( sponsor ) ;
35- return amount >= 5 ;
36- } ) ;
37- } ;
38-
39- export const isSpecialSponsor = ( sponsor : Sponsor ) : boolean => {
40- const amount = getSponsorAmount ( sponsor ) ;
41- return amount >= SPECIAL_SPONSOR_THRESHOLD ;
11+ // Only show lifetime total if totalProcessedAmount exists and tierName is present
12+ return sponsor . totalProcessedAmount !== undefined && ! ! sponsor . tierName ;
4213} ;
4314
4415export const isLifetimeSpecialSponsor = ( sponsor : Sponsor ) : boolean => {
4516 const lifetimeAmount = calculateLifetimeContribution ( sponsor ) ;
4617 return lifetimeAmount >= SPECIAL_SPONSOR_THRESHOLD ;
4718} ;
4819
49- export const sortSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
50- return sponsors . sort ( ( a , b ) => {
51- const aAmount = getSponsorAmount ( a ) ;
52- const bAmount = getSponsorAmount ( b ) ;
53- const aIsSpecial = isSpecialSponsor ( a ) ;
54- const bIsSpecial = isSpecialSponsor ( b ) ;
55-
56- // 1. Special sponsors (>=$100) come first
57- if ( aIsSpecial && ! bIsSpecial ) return - 1 ;
58- if ( ! aIsSpecial && bIsSpecial ) return 1 ;
59- if ( aIsSpecial && bIsSpecial ) {
60- if ( aAmount !== bAmount ) {
61- return bAmount - aAmount ;
62- }
63- // If amounts equal, sort by name
64- return a . name . localeCompare ( b . name ) ;
65- }
66-
67- // 2. Regular sponsors sorted by amount (highest first)
68- if ( aAmount !== bAmount ) {
69- return bAmount - aAmount ;
70- }
71-
72- // 3. If amounts equal, sort by name
73- return a . name . localeCompare ( b . name ) ;
74- } ) ;
75- } ;
76-
77- export const sortSpecialSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
78- return sponsors . sort ( ( a , b ) => {
79- const aLifetime = calculateLifetimeContribution ( a ) ;
80- const bLifetime = calculateLifetimeContribution ( b ) ;
81-
82- // Sort by lifetime contribution (highest first)
83- if ( aLifetime !== bLifetime ) {
84- return bLifetime - aLifetime ;
85- }
86-
87- // If amounts equal, sort by name
88- return a . name . localeCompare ( b . name ) ;
89- } ) ;
90- } ;
91-
92- export const filterCurrentSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
93- // In the new structure, all sponsors in the main arrays are current
94- return sponsors ;
95- } ;
96-
97- export const filterPastSponsors = ( _sponsors : Sponsor [ ] ) : Sponsor [ ] => {
98- // Past sponsors are handled separately in the new structure
99- void _sponsors ;
100- return [ ] ;
101- } ;
102-
103- export const filterSpecialSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
104- return sponsors . filter ( isSpecialSponsor ) ;
105- } ;
20+ export const getSponsorUrl = ( sponsor : Sponsor ) : string => {
21+ const url = sponsor . websiteUrl || sponsor . githubUrl ;
10622
107- export const filterRegularSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
108- return sponsors . filter ( ( sponsor ) => ! isSpecialSponsor ( sponsor ) ) ;
109- } ;
23+ // Ensure URL has a protocol
24+ if ( url && ! url . startsWith ( "http://" ) && ! url . startsWith ( "https://" ) ) {
25+ return `https://${ url } ` ;
26+ }
11027
111- export const getSponsorUrl = ( sponsor : Sponsor ) : string => {
112- return sponsor . websiteUrl || sponsor . githubUrl ;
28+ return url ;
11329} ;
11430
11531export const formatSponsorUrl = ( url : string ) : string => {
0 commit comments