From bb96de135593099f5d5c510be3e9e4e0d53835fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Hodierne?= Date: Wed, 16 Sep 2020 13:51:07 +0200 Subject: [PATCH] implement Open Collective categories for extended filtering --- docs/_data/supporters.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/_data/supporters.js b/docs/_data/supporters.js index 8af54b167d..9db8f3dfca 100755 --- a/docs/_data/supporters.js +++ b/docs/_data/supporters.js @@ -30,9 +30,21 @@ const blocklist = new Set(require('./blocklist.json')); */ const BLOCKED_STRINGS = /(?:vpn|[ck]a[sz]ino|seo|slots|gambl(?:e|ing)|crypto)/i; +/** + * Add a few Categories exposed by Open Collective to help moderation + */ +const BLOCKED_CATEGORIES = [ + 'adult', + 'casino', + 'credit', + 'gambling', + 'seo', + 'writer' +]; + /** * The OC API endpoint - + */ const API_ENDPOINT = 'https://api.opencollective.com/graphql/v2'; @@ -56,6 +68,7 @@ const SUPPORTER_QUERY = `query account($limit: Int, $offset: Int, $slug: String) imgUrlMed: imageUrl(height:64) imgUrlSmall: imageUrl(height:32) type + categories } totalDonations { value @@ -79,7 +92,8 @@ const nodeToSupporter = node => ({ imgUrlSmall: node.fromAccount.imgUrlSmall, firstDonation: node.createdAt, totalDonations: node.totalDonations.value * 100, - type: node.fromAccount.type + type: node.fromAccount.type, + categories: node.fromAccount.categories }); const fetchImage = async supporter => { @@ -140,8 +154,10 @@ const getAllOrders = async (slug = 'mochajs') => { } }; -const isAllowed = ({slug}) => - !blocklist.has(slug) && !BLOCKED_STRINGS.test(slug); +const isAllowed = ({slug, categories}) => + !blocklist.has(slug) && + !BLOCKED_STRINGS.test(slug) && + !categories.some(category => BLOCKED_CATEGORIES.includes(category)); const getSupporters = async () => { const orders = await getAllOrders();