File tree Expand file tree Collapse file tree 3 files changed +32
-30
lines changed
components/Common/Partners Expand file tree Collapse file tree 3 files changed +32
-30
lines changed Original file line number Diff line number Diff line change 33import Tooltip from '@node-core/ui-components/Common/Tooltip' ;
44import * as PartnerLogos from '@node-core/ui-components/Icons/PartnerLogos' ;
55
6- import { providePartners } from '#site/next-data/providers/partners' ;
6+ import providePartners from '#site/next-data/providers/partners' ;
77import { partners } from '#site/next.json.mjs' ;
88
99import type { Partner , PartnerCategory } from '#site/types' ;
@@ -76,8 +76,10 @@ const PartnersList: FC<PartnersListProps> = async ({
7676} ) => {
7777 const isSmall = size === 'small' ;
7878
79+ const SMALL_PARTNER_LIMIT = 6 ;
80+
7981 const partners = await getPartners (
80- length ?? ( isSmall ? 6 : undefined ) ,
82+ length ?? ( isSmall ? SMALL_PARTNER_LIMIT : undefined ) ,
8183 category ,
8284 sort
8385 ) ;
Original file line number Diff line number Diff line change 1+ import { partners } from '#site/next.json.mjs' ;
2+ import { shuffle } from '#site/util/array' ;
3+
4+ /**
5+ * Provides the weighted and shuffled partners array.
6+ * Results are cached using React's cache directive.
7+ * @param seed - The seed for deterministic shuffling
8+ * @param category - Optional category to filter partners
9+ */
10+ const providePartners = async ( seed , category ) => {
11+ // Create weighted array (duplicates based on weight)
12+ const weightedPartners = partners . flatMap ( partner => {
13+ const weight = partner . weight ?? 0 ;
14+ return Array ( weight > 0 ? weight : 1 ) . fill ( partner ) ;
15+ } ) ;
16+
17+ // Shuffle and remove duplicates
18+ const shuffled = await shuffle ( weightedPartners , seed ) ;
19+ const unique = Array . from ( new Set ( shuffled ) ) ;
20+
21+ return category
22+ ? unique . filter ( p => p . categories . includes ( category ) )
23+ : unique ;
24+ } ;
25+
26+ export default providePartners ;
Original file line number Diff line number Diff line change 11'use cache' ;
22
3- import { partners } from '#site/next.json.mjs' ;
4- import { shuffle } from '#site/util/array' ;
3+ import providePartners from '#site/next-data/generators/partners.mjs' ;
54
6- import type { Partner , PartnerCategory } from '#site/types' ;
7-
8- /**
9- * Provides the weighted and shuffled partners array.
10- * Results are cached using React's cache directive.
11- * @param seed - The seed for deterministic shuffling
12- * @param category - Optional category to filter partners
13- */
14- export const providePartners = async (
15- seed : number ,
16- category ?: PartnerCategory
17- ) : Promise < Array < Partner > > => {
18- // Create weighted array (duplicates based on weight)
19- const weightedPartners = partners . flatMap ( partner => {
20- const weight = partner . weight ?? 0 ;
21- return Array ( weight > 0 ? weight : 1 ) . fill ( partner ) ;
22- } ) ;
23-
24- // Shuffle and remove duplicates
25- const shuffled = await shuffle ( weightedPartners , seed ) ;
26- const unique = Array . from ( new Set ( shuffled ) ) ;
27-
28- return category
29- ? unique . filter ( p => p . categories . includes ( category ) )
30- : unique ;
31- } ;
5+ export default providePartners ;
You can’t perform that action at this time.
0 commit comments