Skip to content

Commit 463154d

Browse files
committed
Initial queries
1 parent ed412d8 commit 463154d

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

src/components/Sponsors.astro

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
const GITHUB_TOKEN = import.meta.env.GITHUB_TOKEN;
3+
4+
const gitHubQuery = `query {
5+
organization(login:"tauri-apps") {
6+
sponsors(first: 100) {
7+
nodes {
8+
... on Actor {
9+
login,
10+
avatarUrl
11+
}
12+
}
13+
}
14+
}
15+
}`;
16+
17+
type Sponsor = {
18+
login: string;
19+
avatarUrl: string;
20+
amount?: number;
21+
};
22+
23+
const gitHubSponsors: Sponsor[] = await fetch('https://api.github.com/graphql', {
24+
method: 'POST',
25+
body: JSON.stringify({ query: gitHubQuery }),
26+
headers: {
27+
"Authorization": `bearer ${GITHUB_TOKEN}`
28+
},
29+
}).then(async (response) => {
30+
if (response.ok) {
31+
const data = await response.json();
32+
return data.data.organization.sponsors.nodes;
33+
}
34+
throw Error(
35+
`There was an issue with the GitHub sponsors query: ${response.status}: ${response.statusText}`
36+
);
37+
});
38+
39+
// Documentation at https://graphql-docs-v2.opencollective.com/welcome
40+
const openCollectiveQuery = `query account {
41+
account(slug: "tauri") {
42+
transactions(kind: CONTRIBUTION) {
43+
nodes {
44+
fromAccount {
45+
name
46+
imageUrl
47+
}
48+
amount {
49+
value
50+
}
51+
}
52+
}
53+
}
54+
}`;
55+
56+
const openCollectiveSponsors: Sponsor[] = await fetch('https://api.opencollective.com/graphql/v2', {
57+
method: 'POST',
58+
body: JSON.stringify({ query: openCollectiveQuery }),
59+
headers: {
60+
'Content-Type': 'application/json',
61+
},
62+
}).then(async (response) => {
63+
if (response.ok) {
64+
const data = await response.json();
65+
return data.data.account.transactions.nodes.map(
66+
(node: any) => ({
67+
login: node.fromAccount.name,
68+
avatarUrl: node.fromAccount.imageUrl,
69+
amount: node.amount.value
70+
})
71+
);
72+
}
73+
throw Error(
74+
`There was an issue with the Open Collective sponsors query: ${response.status} ${response.statusText}`
75+
);
76+
});
77+
78+
// TODO: Need to loop over the Open Collective array to merge them based on the login and sum up the amount value (then sort by amount largest to smallest)
79+
---
80+
81+
<h1>Sponsors</h1>
82+
<h2>Open Collective</h2>
83+
<ul>
84+
{openCollectiveSponsors.map((sponsor) => <li>{sponsor.login}</li>)}
85+
</ul>
86+
<h2>GitHub</h2>
87+
<ul>
88+
{gitHubSponsors.map((sponsor) => <li>{sponsor.login}</li>)}
89+
</ul>
90+

src/content/docs/index.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
3737
<div class="bg-grad-red"></div>
3838
</div>
3939

40-
<CardGrid stagger>
40+
{/* <CardGrid stagger>
4141
<Card title="Frontend Independent" icon="rocket">
4242
Bring your existing web stack to Tauri or start that new dream project.
4343
Tauri supports any frontend framework so you don't need to change your
@@ -63,4 +63,8 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
6363
With performance and security at the center, Rust is the language for the
6464
next generation of apps.
6565
</Card>
66-
</CardGrid>
66+
</CardGrid> */}
67+
68+
import Sponsors from '@components/Sponsors.astro'
69+
70+
<Sponsors />

0 commit comments

Comments
 (0)