-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fetch sponsors at build time, show ALL non-skeevy sponsors; closes #4271 #4272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
18b1745
[DO NOT MERGE] show all sponsors on site
boneskull 76f2142
use smaller imgs for backers
boneskull 7aed14e
Fetch all open collective sponsor images to save their dimensions
Munter 74b92e0
Reworked avatars. LEss reflows due to image dimensions. Smoother load…
Munter c9e9bcc
Add standardised lazy loading to all images
Munter 6c01d2e
Set height on badges to avoid page reflows
Munter 10bb5d4
Add node version specification in .nvmrc to get netlify up to date
Munter a84ad17
Move avatars javascript to external file for better development exper…
Munter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| 12 |
This file contains hidden or 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 hidden or 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,133 @@ | ||
| #!/usr/bin/env node | ||
| 'use strict'; | ||
|
|
||
| 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'; | ||
|
|
||
| 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 | ||
| imgUrlMed: imageUrl(height:64) | ||
| imgUrlSmall: imageUrl(height:32) | ||
| type | ||
| } | ||
| totalDonations { | ||
| value | ||
| } | ||
| createdAt | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
|
|
||
| const graphqlPageSize = 1000; | ||
|
|
||
| const nodeToSupporter = node => ({ | ||
| name: node.fromAccount.name, | ||
| slug: node.fromAccount.slug, | ||
| website: node.fromAccount.website, | ||
| imgUrlMed: node.fromAccount.imgUrlMed, | ||
| imgUrlSmall: node.fromAccount.imgUrlSmall, | ||
| 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) => { | ||
| if (supporter.type === 'INDIVIDUAL') { | ||
| supporters.backers.push({ | ||
| ...supporter, | ||
| avatar: supporter.imgUrlSmall | ||
| }); | ||
| } else { | ||
| supporters.sponsors.push({...supporter, avatar: supporter.imgUrlMed}); | ||
| } | ||
| return supporters; | ||
| }, | ||
| {sponsors: [], backers: []} | ||
| ); | ||
|
|
||
| // Fetch images for sponsors and save their image dimensions | ||
| 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, | ||
| supporters.sponsors.length, | ||
| supporters.backers.length + supporters.sponsors.length | ||
| ); | ||
| return supporters; | ||
| }; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,68 @@ | ||
| ## Sponsors | ||
|
|
||
| Use Mocha at Work? Ask your manager or marketing team if they'd help [support](https://opencollective.com/mochajs#support) our project. Your company's logo will also be displayed on [npmjs.com](http://npmjs.com/package/mocha) and our [GitHub repository](https://github.com/mochajs/mocha#sponsors). | ||
|
|
||
| <ul class="image-list" id="sponsors"> | ||
| {%- for supporter in supporters.sponsors -%} | ||
| <li> | ||
| {%- if supporter.website -%} | ||
| <a href="{{ supporter.website }}" target="_blank" rel="noopener" title="{{ supporter.name }}"> | ||
| {%- endif -%} | ||
| <img src="{{ supporter.avatar }}" width="{{ supporter.dimensions.width }}" height="{{ supporter.dimensions.height }}" alt="{{ supporter.name }}" /> | ||
| {%- if supporter.website -%} | ||
| </a> | ||
| {%- endif -%} | ||
| </li> | ||
| {%- endfor -%} | ||
| </ul> | ||
|
|
||
| ## Backers | ||
|
|
||
| Find Mocha helpful? Become a [backer](https://opencollective.com/mochajs#support) and support Mocha with a monthly donation. | ||
|
|
||
| <ul class="image-list faded-images" 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> | ||
|
|
||
| <script> | ||
| (function() { | ||
| 'use strict'; | ||
|
|
||
| var imageLists = document.querySelectorAll('.image-list'); | ||
|
|
||
| function getListItem(img) { | ||
| var parent = img.parentNode; | ||
| while (parent && parent.nodeName !== 'LI') { | ||
| parent = parent.parentNode; | ||
| } | ||
|
|
||
| return parent; | ||
| } | ||
|
|
||
| function onloadHandler() { | ||
| getListItem(this).classList.add('is-loaded'); | ||
| } | ||
|
|
||
| Array.prototype.forEach.call(imageLists, function(imageList) { | ||
| var images = imageList.querySelectorAll('img'); | ||
|
|
||
| for (var i = 0; i < images.length; i += 1) { | ||
| if (!images[i].complete) { | ||
| getListItem(images[i]).classList.add('faded-image'); | ||
| images[i].onload = onloadHandler; | ||
| images[i].onerror = onloadHandler; | ||
| } | ||
| } | ||
| }); | ||
| })(); | ||
| </script> | ||
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.