Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DO NOT MERGE] show all sponsors on site
- change ordering: sponsors, then backers - blacklist bad actors - rename `default.html` to `default.liquid`, because it's a Liquid template. - fiddles with the CSS a bit - do not attempt to display a link if there is no website
- Loading branch information
Showing
10 changed files
with
226 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[ | ||
"cheap-writing-service", | ||
"emailmarketingservices-io", | ||
"device-tricks1", | ||
"my-true-media", | ||
"yiannakis-ttafounas-ttafounas", | ||
"writerseperhour", | ||
"casinotop-com", | ||
"casino-topp", | ||
"casinoutanreg", | ||
"supercazino-ro", | ||
"igor-noskov", | ||
"blue-link-seo", | ||
"casino-online", | ||
"domywriting", | ||
"writemypaper4me", | ||
"trust-my-paper", | ||
"seowebsitetraffic-net", | ||
"pfannen-test", | ||
"mochajs" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const debug = require('debug')('mocha:docs:data:supporters'); | ||
const needle = require('needle'); | ||
const blacklist = new Set(require('./blacklist.json')); | ||
|
||
const API_ENDPOINT = 'https://api.opencollective.com/graphql/v2'; | ||
|
||
const query = `query account($limit: Int, $offset: Int, $slug: String) { | ||
account(slug: $slug) { | ||
orders(limit: $limit, offset: $offset) { | ||
limit | ||
offset | ||
totalCount | ||
nodes { | ||
fromAccount { | ||
name | ||
slug | ||
website | ||
avatar: imageUrl(height:64) | ||
type | ||
} | ||
totalDonations { | ||
value | ||
} | ||
createdAt | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
const graphqlPageSize = 1000; | ||
|
||
const nodeToSupporter = node => ({ | ||
name: node.fromAccount.name, | ||
slug: node.fromAccount.slug, | ||
website: node.fromAccount.website, | ||
avatar: node.fromAccount.avatar, | ||
firstDonation: node.createdAt, | ||
totalDonations: node.totalDonations.value * 100, | ||
type: node.fromAccount.type | ||
}); | ||
|
||
/** | ||
* Retrieves donation data from OC | ||
* | ||
* Handles pagination | ||
* @param {string} slug - Collective slug to get donation data from | ||
* @returns {Promise<Object[]>} Array of raw donation data | ||
*/ | ||
const getAllOrders = async (slug = 'mochajs') => { | ||
let allOrders = []; | ||
const variables = {limit: graphqlPageSize, offset: 0, slug}; | ||
|
||
// Handling pagination if necessary (2 pages for ~1400 results in May 2019) | ||
while (true) { | ||
const result = await needle( | ||
'post', | ||
API_ENDPOINT, | ||
{query, variables}, | ||
{json: true} | ||
); | ||
const orders = result.body.data.account.orders.nodes; | ||
allOrders = [...allOrders, ...orders]; | ||
variables.offset += graphqlPageSize; | ||
if (orders.length < graphqlPageSize) { | ||
debug('retrieved %d orders', allOrders.length); | ||
return allOrders; | ||
} else { | ||
debug( | ||
'loading page %d of orders...', | ||
Math.floor(variables.offset / graphqlPageSize) | ||
); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = async () => { | ||
const orders = await getAllOrders(); | ||
// Deduplicating supporters with multiple orders | ||
const uniqueSupporters = new Map(); | ||
|
||
const supporters = orders | ||
.map(nodeToSupporter) | ||
.filter(supporter => !blacklist.has(supporter.slug)) | ||
.reduce((supporters, supporter) => { | ||
if (uniqueSupporters.has(supporter.slug)) { | ||
// aggregate donation totals | ||
uniqueSupporters.get(supporter.slug).totalDonations += | ||
supporter.totalDonations; | ||
return supporters; | ||
} | ||
uniqueSupporters.set(supporter.slug, supporter); | ||
return [...supporters, supporter]; | ||
}, []) | ||
.sort((a, b) => b.totalDonations - a.totalDonations) | ||
.reduce( | ||
(supporters, supporter) => { | ||
supporters[ | ||
supporter.type === 'INDIVIDUAL' ? 'backers' : 'sponsors' | ||
].push(supporter); | ||
return supporters; | ||
}, | ||
{sponsors: [], backers: []} | ||
); | ||
|
||
debug( | ||
'found %d valid backers and %d valid sponsors (%d total)', | ||
supporters.backers.length, | ||
supporters.sponsors.length, | ||
supporters.backers.length + supporters.sponsors.length | ||
); | ||
return supporters; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
## Backers | ||
|
||
Find Mocha helpful? Become a [backer](https://opencollective.com/mochajs#support) and support Mocha with a monthly donation. | ||
Find Mocha helpful? Become a [backer](https://opencollective.com/mochajs#support) and support Mocha with a monthly donation. | ||
|
||
<!-- markdownlint-disable MD034 --> | ||
{% for i in (0..29) %}[![](https://opencollective.com/mochajs/backer/{{ i }}/avatar.jpg)](https://opencollective.com/mochajs/backer/{{ i }}/website){: target="_blank" rel="noopener"}{% endfor %} | ||
{: .image-list id="_backers" } | ||
{% comment %} | ||
Do not remove whitespace below! | ||
{% endcomment %} | ||
|
||
<ul class="image-list" id="backers"> | ||
{% for supporter in supporters.backers %}<li>{% if supporter.website %}<a href="{{ supporter.website }}" target="_blank" rel="noopener" title="{{ supporter.name }}">{% endif %}<img src="{{ supporter.avatar }}" alt="{{ supporter.name }}" />{% if supporter.website %}</a>{% endif %}</li>{% endfor %} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,5 +170,7 @@ <h1> | |
</dd> | ||
</dl> | ||
</footer> | ||
|
||
<script src="js/avatars.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.