freeCodeCamp/client/plugins/fcc-source-challenges/create-challenge-nodes.js
Oliver Eyton-Williams 4b14f9297b
fix: source certificates into Gatsby (#39648)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
2020-09-24 16:04:35 +05:30

44 lines
1.1 KiB
JavaScript

const crypto = require('crypto');
function createChallengeNode(challenge, reporter) {
// challengeType 11 is for video challenges (they only have instructions)
// challengeType 7 is for certificates (they only have tests)
if (
typeof challenge.description[0] !== 'string' &&
(challenge.challengeType !== 11 && challenge.challengeType !== 7)
) {
reporter.warn(`
${challenge.title} has a description that will break things!
`);
}
const contentDigest = crypto
.createHash('md5')
.update(JSON.stringify(challenge))
.digest('hex');
const internal = {
contentDigest,
type: challenge.challengeType === 7 ? 'CertificateNode' : 'ChallengeNode'
};
/* eslint-disable prefer-object-spread/prefer-object-spread */
return JSON.parse(
JSON.stringify(
Object.assign(
{},
{
children: [],
parent: null,
internal,
sourceInstanceName: 'challenge'
},
challenge,
{ id: challenge.id + internal.type }
)
)
);
}
exports.createChallengeNode = createChallengeNode;