|
1 | 1 | (function(){
|
2 | 2 | var services = [
|
3 |
| - 'https://opencollective.com/api/groups/gulpjs/backers', |
| 3 | + 'https://rest.opencollective.com/v2/gulpjs/orders/incoming?status=active,cancelled,paid&limit=1000', |
4 | 4 | 'https://api.npmjs.org/downloads/point/last-week/gulp',
|
5 | 5 | 'https://api.npms.io/v2/search?q=keywords%3Agulpplugin',
|
6 | 6 | ].map(function (url) {
|
|
11 | 11 | return resp.json();
|
12 | 12 | }
|
13 | 13 |
|
| 14 | + function uniqueBySlug(array) { |
| 15 | + var predicate = function (o) { |
| 16 | + return o.fromAccount.slug; |
| 17 | + } |
| 18 | + return array.reduce(function(acc, curr) { |
| 19 | + return acc.filter(function (a) { |
| 20 | + return predicate(a) === predicate(curr); |
| 21 | + }).length ? acc : acc.push(curr) && acc |
| 22 | + }, []); |
| 23 | + } |
| 24 | + |
| 25 | + function sortByTotalDonations(a, b) { |
| 26 | + return b.totalDonations.value - a.totalDonations.value; |
| 27 | + } |
| 28 | + |
14 | 29 | var supporters = services[0];
|
15 | 30 | var downloads = services[1];
|
16 | 31 | var plugins = services[2];
|
|
42 | 57 | }
|
43 | 58 | })
|
44 | 59 |
|
45 |
| - supporters.then(function (entries) { |
| 60 | + supporters.then(function (orders) { |
46 | 61 | var fragment = document.createDocumentFragment();
|
47 | 62 | var nodes = [];
|
48 |
| - var supportersToDisplay = entries.slice(0, 10); |
| 63 | + var uniqueSupporters = uniqueBySlug(orders.nodes.sort(sortByTotalDonations)); |
| 64 | + var supportersToDisplay = uniqueSupporters.slice(0, 10); |
49 | 65 |
|
50 | 66 | supportersToDisplay.forEach(function(supporter) {
|
| 67 | + var fromAccount = supporter.fromAccount; |
| 68 | + var totalDonations = supporter.totalDonations; |
| 69 | + |
| 70 | + var name = fromAccount.name; |
| 71 | + var slug = fromAccount.slug; |
| 72 | + var website = fromAccount.website; |
| 73 | + var twitterHandle = fromAccount.twitterHandle; |
| 74 | + var imageUrl = fromAccount.imageUrl; |
| 75 | + |
51 | 76 | var img = new Image();
|
52 |
| - img.src = supporter.avatar; |
| 77 | + img.src = imageUrl; |
53 | 78 | img.width = 80;
|
54 | 79 | img.onload = function(e) {
|
55 | 80 | e.currentTarget.parentNode.classList.remove('supporter--skeleton');
|
56 | 81 | }
|
| 82 | + img.alt = name; |
57 | 83 |
|
58 | 84 | var link = document.createElement('a');
|
59 | 85 | link.className = 'supporter supporter--skeleton';
|
60 | 86 | link.rel = 'nofollow';
|
61 |
| - if (supporter.website) { |
62 |
| - link.href = supporter.website; |
63 |
| - img.alt = supporter.website; |
64 |
| - } else if (supporter.twitterHandle) { |
65 |
| - link.href = 'https://twitter.com/' + supporter.twitterHandle |
66 |
| - img.alt = supporter.twitterHandle; |
| 87 | + link.title = name + ' with $' + totalDonations.value + ' total'; |
| 88 | + |
| 89 | + if (website) { |
| 90 | + link.href = website; |
| 91 | + } else if (twitterHandle) { |
| 92 | + link.href = 'https://twitter.com/' + twitterHandle |
67 | 93 | } else {
|
68 |
| - link.href = 'https://opencollective.com/' + supporter.slug |
69 |
| - img.alt = supporter.slug; |
| 94 | + link.href = 'https://opencollective.com/' + slug |
70 | 95 | }
|
71 | 96 |
|
72 | 97 | link.appendChild(img);
|
|
0 commit comments