Skip to content

Commit

Permalink
Add tweets and headline sponsors to website (#3572)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Jan 2, 2024
1 parent a018775 commit 040362c
Show file tree
Hide file tree
Showing 18 changed files with 5,947 additions and 8,836 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ we'd like to work with you:

1. File an issue on GitHub describing the contribution you'd like to make. This
will help us to get you started on the right foot.
2. Create a single commit that addresses the issue:
2. Fork the project, and make your changes in a new branch based off of the
`main` branch:
1. Follow the project's code style (see below)
2. Add enough unit tests to "prove" that your patch is correct
3. Update the project documentation as needed (see below)
Expand Down
20 changes: 17 additions & 3 deletions scripts/fetch-sponsors.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Sponsor {
url: string;
type: 'ORGANIZATION' | 'INDIVIDUAL' | 'FUND';
monthlyDonation: number;
totalDonations: number;
source: 'github' | 'opencollective' | 'manual';
tier: Tier | null;
}
Expand All @@ -33,6 +34,7 @@ const tierSponsors: Record<Tier, Sponsor[]> = {
url: 'https://tidelift.com/subscription/pkg/npm-cheerio',
type: 'FUND',
monthlyDonation: 0,
totalDonations: 0,
source: 'manual',
tier: 'headliner',
},
Expand All @@ -43,6 +45,7 @@ const tierSponsors: Record<Tier, Sponsor[]> = {
url: 'https://github.com/',
type: 'ORGANIZATION',
monthlyDonation: 0,
totalDonations: 0,
source: 'manual',
tier: 'headliner',
},
Expand All @@ -53,6 +56,7 @@ const tierSponsors: Record<Tier, Sponsor[]> = {
url: 'https://www.airbnb.com/',
type: 'ORGANIZATION',
monthlyDonation: 0,
totalDonations: 0,
source: 'manual',
tier: 'headliner',
},
Expand Down Expand Up @@ -141,7 +145,7 @@ async function fetchOpenCollectiveSponsors(): Promise<Sponsor[]> {

const payload = await body.json();

return payload.data.account.orders.nodes.map((order: any) => {
return payload.data.account.orders.nodes.map((order: any): Sponsor => {
const donation = order.amount.value * 100;
const monthlyDonation =
order.frequency === 'YEARLY' ? Math.round(donation / 12) : donation;
Expand All @@ -160,6 +164,13 @@ async function fetchOpenCollectiveSponsors(): Promise<Sponsor[]> {
});
}

function getMonthsActive(date: string): number {
const now = new Date();
const then = new Date(date);
const months = (now.getFullYear() - then.getFullYear()) * 12;
return months - then.getMonth() + now.getMonth() + 1;
}

/**
* Fetches GitHub Sponsors data using the GraphQL API.
*
Expand Down Expand Up @@ -207,7 +218,7 @@ async function fetchGitHubSponsors(): Promise<Sponsor[]> {

// Return an array in the same format as Open Collective
return organization.sponsorshipsAsMaintainer.nodes.map(
({ sponsor, tier, createdAt }: any) => ({
({ sponsor, tier, createdAt }: any): Sponsor => ({
createdAt,
name: sponsor.name,
image: `${sponsor.avatarUrl}&s=128`,
Expand All @@ -216,6 +227,8 @@ async function fetchGitHubSponsors(): Promise<Sponsor[]> {
// Workaround to get the type — fetch a field that only exists on users.
sponsor.isViewer === undefined ? 'ORGANIZATION' : 'INDIVIDUAL',
monthlyDonation: tier.monthlyPriceInDollars * 100,
totalDonations:
getMonthsActive(createdAt) * tier.monthlyPriceInDollars * 100,
source: 'github',
tier: getTierSlug(tier.monthlyPriceInDollars),
}),
Expand Down Expand Up @@ -285,11 +298,12 @@ for (const sponsor of sponsors) {

for (const tier of Object.values(tierSponsors)) {
// Sort order based on total donations
tier.sort((a: Sponsor, b: Sponsor) => b.monthlyDonation - a.monthlyDonation);
tier.sort((a: Sponsor, b: Sponsor) => b.totalDonations - a.totalDonations);

// Set all montly donations to 0
for (const sponsor of tier) {
sponsor.monthlyDonation = 0;
sponsor.totalDonations = 0;
}
}

Expand Down
4 changes: 3 additions & 1 deletion website/docs/basics/loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ Here's an example of how to use the load method:
```js
import * as cheerio from 'cheerio';

const $ = cheerio.load('<html><body><h1>Hello, world!</h1></body></html>');
const $ = cheerio.load(
'<html><head><title>Hello, world!</title></head></html>',
);

console.log($('h1').text());
// Output: Hello, world!
Expand Down
12 changes: 3 additions & 9 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const config = {
label: 'Tutorial',
},
{
to: 'docs/api/',
to: 'docs/api',
label: 'API',
position: 'left',
},
Expand All @@ -102,7 +102,7 @@ const config = {
},
{
label: 'API',
to: 'docs/api/',
to: 'docs/api',
},
],
},
Expand Down Expand Up @@ -221,7 +221,7 @@ const config = {
'xml',
].map((name) => `/functions/${name}.html`),
],
to: `/docs/api/`,
to: '/docs/api',
},
],
}),
Expand All @@ -233,16 +233,10 @@ const config = {
// TypeDoc options
entryPoints: ['../src/batteries.ts'],
tsconfig: '../tsconfig.json',
plugin: ['./typedoc/typedoc-plugin-class-fns-to-methods.cjs'],
readme: 'none',
excludePrivate: true,

externalSymbolLinkMappings: {
typescript: {
Promise:
'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise',
URL: 'https://developer.mozilla.org/en-US/docs/Web/API/URL',
},
domhandler: {
Document: 'https://domhandler.js.org/classes/Document.html',
Element: 'https://domhandler.js.org/classes/Element.html',
Expand Down
Loading

0 comments on commit 040362c

Please sign in to comment.