Skip to content

Commit 84f513f

Browse files
authored
chore: implement backers component
1 parent 73b74d8 commit 84f513f

File tree

5 files changed

+124
-0
lines changed

5 files changed

+124
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Avatar from '@node-core/ui-components/Common/AvatarGroup/Avatar';
2+
import type { FC, PropsWithChildren } from 'react';
3+
4+
import provideBackers from '#site/next-data/providers/backersData';
5+
6+
const WithBackers: FC<PropsWithChildren> = () => {
7+
const backers = provideBackers();
8+
9+
return (
10+
<div className="flex max-w-full flex-wrap items-center justify-center gap-1">
11+
{backers.map(({ name, image, url }, i) => (
12+
<Avatar nickname={name} image={image} url={url} key={`${name}-${i}`} />
13+
))}
14+
</div>
15+
);
16+
};
17+
18+
export default WithBackers;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// This is used to ensure that URLs are always in the correct format
2+
function fixUrl(url) {
3+
if (!url) {
4+
return null;
5+
}
6+
7+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
8+
return `https://${url}`;
9+
}
10+
11+
return url;
12+
}
13+
14+
async function fetchOpenCollectiveData() {
15+
const endpoint = 'https://api.opencollective.com/graphql/v2';
16+
17+
const query = `{
18+
account(slug: "nodejs") {
19+
orders(status: ACTIVE, filter: INCOMING) {
20+
totalCount
21+
nodes {
22+
fromAccount {
23+
name
24+
website
25+
imageUrl
26+
}
27+
amount {
28+
value
29+
}
30+
tier {
31+
slug
32+
}
33+
frequency
34+
totalDonations {
35+
value
36+
}
37+
}
38+
}
39+
}
40+
donations: orders(
41+
account: { slug: "nodejs" }
42+
frequency: ONETIME
43+
status: PAID
44+
filter: INCOMING
45+
) {
46+
totalCount
47+
nodes {
48+
id
49+
updatedAt
50+
frequency
51+
status
52+
amount {
53+
value
54+
currency
55+
}
56+
fromAccount {
57+
name
58+
website
59+
imageUrl
60+
}
61+
}
62+
}
63+
}`;
64+
65+
const response = await fetch(endpoint, {
66+
method: 'POST',
67+
headers: { 'Content-Type': 'application/json' },
68+
body: JSON.stringify({ query }),
69+
});
70+
71+
const payload = await response.json();
72+
73+
const sponsors = payload.data.account.orders.nodes.map(order => ({
74+
name: order.fromAccount.name,
75+
url: fixUrl(order.fromAccount.website),
76+
image: order.fromAccount.imageUrl,
77+
source: 'opencollective',
78+
}));
79+
80+
const donations = payload.data.donations.nodes.map(transaction => ({
81+
name: transaction.fromAccount.name,
82+
url: fixUrl(transaction.fromAccount.website),
83+
image: transaction.fromAccount.imageUrl,
84+
source: 'opencollective',
85+
}));
86+
87+
sponsors.push(...donations);
88+
89+
return sponsors;
90+
}
91+
92+
export { fetchOpenCollectiveData };
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { cache } from 'react';
2+
3+
import { fetchOpenCollectiveData } from '#site/next-data/generators/backersData.mjs';
4+
5+
const github = await fetchOpenCollectiveData();
6+
7+
const provideBackers = cache(() => [...github]);
8+
9+
export default provideBackers;

apps/site/next.mdx.use.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import PartnersIconList from './components/Common/Partners/PartnersIconList';
66
import PartnersLogoList from './components/Common/Partners/PartnersLogoList';
77
import DownloadReleasesTable from './components/Downloads/DownloadReleasesTable';
88
import UpcomingMeetings from './components/MDX/Calendar/UpcomingMeetings';
9+
import WithBackers from './components/withBackers';
910
import WithBadgeGroup from './components/withBadgeGroup';
1011
import WithBanner from './components/withBanner';
1112
import WithNodeRelease from './components/withNodeRelease';
@@ -23,6 +24,8 @@ export const mdxComponents = {
2324
WithBanner,
2425
// HOC for providing Badge Data
2526
WithBadgeGroup,
27+
// HOC for providing Backers Data
28+
WithBackers,
2629
// Shows a list of Node.js Partners with Icons
2730
PartnersIconList,
2831
// Shows a list of Node.js Partners with Logos

apps/site/pages/en/about/partners.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Projects with their logo, name, tier, the description and a CTA button
4141

4242
Show a list of lists direct individual or organizational support that can be done through OpenCollective and GitHub Sponsors
4343

44+
<WithBackers />
45+
4446
## Become a Partner
4547

4648
this section isn't in the specification

0 commit comments

Comments
 (0)