From d7faae242235ecaa37d76e0f34f134416cf8dfbb Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Fri, 15 May 2020 15:32:59 -0700 Subject: [PATCH] [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 --- .eslintrc.yml | 1 + docs/_data/blacklist.json | 21 ++++ docs/_data/supporters.js | 115 ++++++++++++++++++ docs/_includes/backers.md | 12 +- .../{default.html => default.liquid} | 2 + docs/_includes/sponsors.md | 11 +- docs/css/style.css | 34 ++++-- docs/index.md | 2 +- package.json | 1 + 9 files changed, 177 insertions(+), 22 deletions(-) create mode 100644 docs/_data/blacklist.json create mode 100644 docs/_data/supporters.js rename docs/_includes/{default.html => default.liquid} (99%) diff --git a/.eslintrc.yml b/.eslintrc.yml index 0834c5c9d2..2a3fa281df 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -36,6 +36,7 @@ overrides: - test/integration/options/watch.spec.js - test/integration/helpers.js - lib/growl.js + - docs/_data/**/*.js parserOptions: ecmaVersion: 2018 env: diff --git a/docs/_data/blacklist.json b/docs/_data/blacklist.json new file mode 100644 index 0000000000..3949526a9b --- /dev/null +++ b/docs/_data/blacklist.json @@ -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" +] diff --git a/docs/_data/supporters.js b/docs/_data/supporters.js new file mode 100644 index 0000000000..f4c9cdc296 --- /dev/null +++ b/docs/_data/supporters.js @@ -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} 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; +}; diff --git a/docs/_includes/backers.md b/docs/_includes/backers.md index 4481202591..72773040f7 100644 --- a/docs/_includes/backers.md +++ b/docs/_includes/backers.md @@ -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. - -{% 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 %} + + diff --git a/docs/_includes/default.html b/docs/_includes/default.liquid similarity index 99% rename from docs/_includes/default.html rename to docs/_includes/default.liquid index cdef5c2276..a8be8a0d56 100644 --- a/docs/_includes/default.html +++ b/docs/_includes/default.liquid @@ -170,5 +170,7 @@

+ + diff --git a/docs/_includes/sponsors.md b/docs/_includes/sponsors.md index 257f9524b1..9605066635 100644 --- a/docs/_includes/sponsors.md +++ b/docs/_includes/sponsors.md @@ -2,9 +2,10 @@ 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). - +{% comment %} +Do not remove whitespace below! +{% endcomment %} -{% for i in (0..15) %}[![](https://opencollective.com/mochajs/sponsor/{{ i }}/avatar.png)](https://opencollective.com/mochajs/sponsor/{{ i }}/website){: target="\_blank"} {% endfor %} -{: .image-list .faded-images} - - + diff --git a/docs/css/style.css b/docs/css/style.css index 39fefea91e..5ec74e4d6a 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -74,28 +74,38 @@ nav.badges a + a { margin-left: 3px; } -.image-list { +ul.image-list { overflow: hidden; text-align: center; + list-style: none; + column-count: 1; + padding: 0; + margin: 0; +} + +ul.image-list li { + border-bottom: none; + display: inline-block; + margin: 0 4px 0 4px; + max-height: 64px; + padding: 0; } -.image-list a { +ul.image-list li a { display: inline-block; - margin: 6px; } -.image-list a img { +ul.image-list li img { + margin: 0; + padding: 0; display: block; - height: 64px; + max-height: 64px; } -.faded-images { - background-color: #ddd; - border: 1px solid; - border-color: #ddd #ddd #ccc; - border-radius: 3px; - padding: 1em; - box-shadow: inset 0 0 10px #ccc; +ul#backers.image-list li img { + width: 64px; + height: 64px; + clip-path: inset(0, 0, 64px, 64px); } .faded-images img { diff --git a/docs/index.md b/docs/index.md index 415430a3d4..e85f8ab42e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -822,7 +822,7 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass -```text +``` mocha [spec..] diff --git a/package.json b/package.json index 73b65cfb12..8201e41a2a 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "markdown-magic-package-json": "^2.0.1", "markdown-toc": "^1.2.0", "markdownlint-cli": "^0.22.0", + "needle": "^2.4.1", "nps": "^5.9.12", "nyc": "^15.0.0", "prettier": "^1.19.1",