Skip to content

Commit

Permalink
Initial queries
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzolewis committed Oct 26, 2023
1 parent ed412d8 commit 463154d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
90 changes: 90 additions & 0 deletions src/components/Sponsors.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
const GITHUB_TOKEN = import.meta.env.GITHUB_TOKEN;
const gitHubQuery = `query {
organization(login:"tauri-apps") {
sponsors(first: 100) {
nodes {
... on Actor {
login,
avatarUrl
}
}
}
}
}`;
type Sponsor = {
login: string;
avatarUrl: string;
amount?: number;
};
const gitHubSponsors: Sponsor[] = await fetch('https://api.github.com/graphql', {
method: 'POST',
body: JSON.stringify({ query: gitHubQuery }),
headers: {
"Authorization": `bearer ${GITHUB_TOKEN}`
},
}).then(async (response) => {
if (response.ok) {
const data = await response.json();
return data.data.organization.sponsors.nodes;
}
throw Error(
`There was an issue with the GitHub sponsors query: ${response.status}: ${response.statusText}`
);
});
// Documentation at https://graphql-docs-v2.opencollective.com/welcome
const openCollectiveQuery = `query account {
account(slug: "tauri") {
transactions(kind: CONTRIBUTION) {
nodes {
fromAccount {
name
imageUrl
}
amount {
value
}
}
}
}
}`;
const openCollectiveSponsors: Sponsor[] = await fetch('https://api.opencollective.com/graphql/v2', {
method: 'POST',
body: JSON.stringify({ query: openCollectiveQuery }),
headers: {
'Content-Type': 'application/json',
},
}).then(async (response) => {
if (response.ok) {
const data = await response.json();
return data.data.account.transactions.nodes.map(
(node: any) => ({
login: node.fromAccount.name,
avatarUrl: node.fromAccount.imageUrl,
amount: node.amount.value
})
);
}
throw Error(
`There was an issue with the Open Collective sponsors query: ${response.status} ${response.statusText}`
);
});
// 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)
---

<h1>Sponsors</h1>
<h2>Open Collective</h2>
<ul>
{openCollectiveSponsors.map((sponsor) => <li>{sponsor.login}</li>)}
</ul>
<h2>GitHub</h2>
<ul>
{gitHubSponsors.map((sponsor) => <li>{sponsor.login}</li>)}
</ul>

8 changes: 6 additions & 2 deletions src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
<div class="bg-grad-red"></div>
</div>

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

import Sponsors from '@components/Sponsors.astro'

<Sponsors />

0 comments on commit 463154d

Please sign in to comment.