Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fetch all open collective sponsor images to save their dimensions
  • Loading branch information
Munter authored and boneskull committed May 20, 2020
commit 7aed14e42d092e52a4dab6a2d0e37e9ddf2c89f2
11 changes: 11 additions & 0 deletions docs/_data/supporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const debug = require('debug')('mocha:docs:data:supporters');
const needle = require('needle');
const imageSize = require('image-size');
const blacklist = new Set(require('./blacklist.json'));

const API_ENDPOINT = 'https://api.opencollective.com/graphql/v2';
Expand Down Expand Up @@ -112,6 +113,16 @@ module.exports = async () => {
{sponsors: [], backers: []}
);

// Fetch images for sponsors and save their image dimensins
await Promise.all(
supporters.sponsors.map(async sponsor => {
for await (const chunk of needle.get(sponsor.avatar)) {
sponsor.dimensions = imageSize(chunk);
break;
}
})
);

debug(
'found %d valid backers and %d valid sponsors (%d total)',
supporters.backers.length,
Expand Down
Loading