Skip to content

Commit

Permalink
docs(showcase): add 74 new showcase sites (#8010)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Aug 31, 2022
1 parent ab73d86 commit 97c9710
Show file tree
Hide file tree
Showing 3 changed files with 674 additions and 12 deletions.
61 changes: 61 additions & 0 deletions website/src/data/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import fs from 'fs-extra';
import path from 'path';
import _ from 'lodash';
import imageSize from 'image-size';
import {Joi} from '@docusaurus/utils-validation';
import {TagList, sortedUsers, type User} from '../users';
Expand Down Expand Up @@ -62,6 +63,7 @@ describe('users data', () => {
// The preview should be jest/emptyModule
preview: Joi.object({default: Joi.any()})
.unknown(false)
.allow(null)
.required()
.messages({
'object.base':
Expand All @@ -87,6 +89,65 @@ describe('users data', () => {
);
}
});

it('does not contain duplicates', () => {
function normalizeUrl(url: string | null) {
if (url === null) {
return null;
}
if (!url.endsWith('/')) {
return `${url}/`;
}
return url;
}

function duplicatesBy(mapper: (user: User) => string | null) {
const grouped: {[key: string]: User[]} = _.groupBy(sortedUsers, (user) =>
mapper(user),
);
return Object.fromEntries(
Object.entries(grouped).filter((entry) => entry[1].length > 1),
);
}

let duplicatesLog = '';

const duplicatesByTitle = duplicatesBy((user) =>
user.title.trim().toLowerCase(),
);
Object.entries(duplicatesByTitle).forEach(([title, users]) => {
duplicatesLog += `Showcase site title '${title}' is used ${users.length} times! Duplicates are not allowed!\n`;
});

const duplicatesByDescription = duplicatesBy((user) =>
user.description.trim().toLowerCase(),
);
Object.entries(duplicatesByDescription).forEach(([description, users]) => {
duplicatesLog += `Showcase site description '${description}' is used ${users.length} times! Duplicates are not allowed!\n`;
});

const duplicatesByWebsite = duplicatesBy((user) =>
normalizeUrl(user.website),
);
Object.entries(duplicatesByWebsite).forEach(([website, users]) => {
duplicatesLog += `Showcase site website url '${website}' is used ${users.length} times! Duplicates are not allowed!\n`;
});

const duplicatesBySource = duplicatesBy((user) =>
normalizeUrl(user.source),
);
Object.entries(duplicatesBySource).forEach(([source, users]) => {
// source is allowed to be null for multiple sites
// "null", see Lodash groupBy issue: https://github.com/lodash/lodash/issues/3060
if (source && source !== 'null') {
duplicatesLog += `Showcase site source url '${source}' is used ${users.length} times! Duplicates are not allowed!\n`;
}
});

if (duplicatesLog) {
throw new Error(duplicatesLog);
}
});
});

describe('preview images', () => {
Expand Down
Loading

0 comments on commit 97c9710

Please sign in to comment.