Files
freeCodeCamp/client/utils/gatsby/challengePageCreator.js
renovate[bot] 21dd80c47a chore(deps): update dependency prettier to v2.3.0 (#42074)
* chore(deps): update dependency prettier to v2.3.0

* chore: apply formating per prettier

* fix: correctly disable import/no-unresolved

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Mrugesh Mohapatra <hi@mrugesh.dev>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-05-10 08:48:49 -07:00

116 lines
2.5 KiB
JavaScript

const path = require('path');
const { dasherize } = require('../../../utils/slugs');
const { viewTypes } = require('../challengeTypes');
const backend = path.resolve(
__dirname,
'../../src/templates/Challenges/projects/backend/Show.js'
);
const classic = path.resolve(
__dirname,
'../../src/templates/Challenges/classic/Show.js'
);
const frontend = path.resolve(
__dirname,
'../../src/templates/Challenges/projects/frontend/Show.js'
);
const intro = path.resolve(
__dirname,
'../../src/templates/Introduction/Intro.js'
);
const superBlockIntro = path.resolve(
__dirname,
'../../src/templates/Introduction/SuperBlockIntro.js'
);
const video = path.resolve(
__dirname,
'../../src/templates/Challenges/video/Show.js'
);
const views = {
backend,
classic,
modern: classic,
frontend,
video
// quiz: Quiz
};
const getNextChallengePath = (node, index, nodeArray) => {
const next = nodeArray[index + 1];
return next ? next.node.fields.slug : '/learn';
};
const getPrevChallengePath = (node, index, nodeArray) => {
const prev = nodeArray[index - 1];
return prev ? prev.node.fields.slug : '/learn';
};
const getTemplateComponent = challengeType => views[viewTypes[challengeType]];
exports.createChallengePages =
createPage =>
({ node }, index, thisArray) => {
const {
superBlock,
block,
fields: { slug },
required = [],
template,
challengeType,
id
} = node;
// TODO: challengeType === 7 and isPrivate are the same, right? If so, we
// should remove one of them.
return createPage({
path: slug,
component: getTemplateComponent(challengeType),
context: {
challengeMeta: {
superBlock,
block,
template,
required,
nextChallengePath: getNextChallengePath(node, index, thisArray),
prevChallengePath: getPrevChallengePath(node, index, thisArray),
id
},
slug
}
});
};
exports.createBlockIntroPages = createPage => edge => {
const {
fields: { slug },
frontmatter: { block }
} = edge.node;
return createPage({
path: slug,
component: intro,
context: {
block: dasherize(block),
slug
}
});
};
exports.createSuperBlockIntroPages = createPage => edge => {
const {
fields: { slug },
frontmatter: { superBlock }
} = edge.node;
return createPage({
path: slug,
component: superBlockIntro,
context: {
superBlock,
slug
}
});
};