Skip to content

Commit

Permalink
implement Open Collective categories for extended filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
znarf authored and boneskull committed Sep 25, 2020
1 parent 28f970e commit bb96de1
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions docs/_data/supporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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
Expand All @@ -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 => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit bb96de1

Please sign in to comment.