Files
freeCodeCamp/client/utils/gatsby/challenge-page-creator.js

127 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-11-29 12:12:15 +00:00
const path = require('path');
const { dasherize } = require('../../../utils/slugs');
2018-11-29 12:12:15 +00:00
const { viewTypes } = require('../challenge-types');
2018-11-29 12:12:15 +00:00
const backend = path.resolve(
__dirname,
'../../src/templates/Challenges/projects/backend/Show.tsx'
2018-11-29 12:12:15 +00:00
);
const classic = path.resolve(
__dirname,
'../../src/templates/Challenges/classic/show.tsx'
2018-11-29 12:12:15 +00:00
);
const frontend = path.resolve(
2018-11-29 12:12:15 +00:00
__dirname,
'../../src/templates/Challenges/projects/frontend/Show.tsx'
2018-11-29 12:12:15 +00:00
);
const codeally = path.resolve(
__dirname,
'../../src/templates/Challenges/codeally/show.tsx'
);
2018-11-29 12:12:15 +00:00
const intro = path.resolve(
__dirname,
feat(client): ts-migrate multiple files (#43262) * feat(client): ts-migrate rename files * feat(client): ts-migrate client/src/templates/Introduction/* * feat(client): ts-migrate client/src/components/formHelpers/form* * fix: import * Update client/src/components/formHelpers/form-validators.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * Update client/src/components/formHelpers/form-fields.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * Update client/src/components/formHelpers/form-fields.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * fix: types in client/src/components/formHelpers/index.tsx * fix: types in client/src/templates/Introduction/super-block-intro.tsx * fix: types in client/src/components/formHelpers/* * fix: signInLoading and value types * Update client/src/templates/Introduction/super-block-intro.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore(deps): update dependency rollup to v2.58.1 * fix: rename variables and fix imports for ts-migrate * fix: remove `Type` suffix from the type definition. * Update client/src/components/formHelpers/form.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-10-25 23:15:36 +05:30
'../../src/templates/Introduction/intro.tsx'
2018-11-29 12:12:15 +00:00
);
const superBlockIntro = path.resolve(
__dirname,
feat(client): ts-migrate multiple files (#43262) * feat(client): ts-migrate rename files * feat(client): ts-migrate client/src/templates/Introduction/* * feat(client): ts-migrate client/src/components/formHelpers/form* * fix: import * Update client/src/components/formHelpers/form-validators.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * Update client/src/components/formHelpers/form-fields.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * Update client/src/components/formHelpers/form-fields.tsx Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> * fix: types in client/src/components/formHelpers/index.tsx * fix: types in client/src/templates/Introduction/super-block-intro.tsx * fix: types in client/src/components/formHelpers/* * fix: signInLoading and value types * Update client/src/templates/Introduction/super-block-intro.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * Update client/src/components/formHelpers/index.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore(deps): update dependency rollup to v2.58.1 * fix: rename variables and fix imports for ts-migrate * fix: remove `Type` suffix from the type definition. * Update client/src/components/formHelpers/form.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Shaun Hamilton <shauhami020@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-10-25 23:15:36 +05:30
'../../src/templates/Introduction/super-block-intro.tsx'
2018-11-29 12:12:15 +00:00
);
const video = path.resolve(
__dirname,
'../../src/templates/Challenges/video/Show.tsx'
);
2018-11-29 12:12:15 +00:00
const views = {
backend,
classic,
modern: classic,
frontend,
video,
codeally
2018-11-29 12:12:15 +00:00
// quiz: Quiz
};
function getNextChallengePath(_node, index, nodeArray) {
2018-11-29 12:12:15 +00:00
const next = nodeArray[index + 1];
return next ? next.node.fields.slug : '/learn';
}
function getPrevChallengePath(_node, index, nodeArray) {
const prev = nodeArray[index - 1];
return prev ? prev.node.fields.slug : '/learn';
}
function getTemplateComponent(challengeType) {
return views[viewTypes[challengeType]];
}
2018-11-29 12:12:15 +00:00
exports.createChallengePages = function (createPage) {
return function ({ 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.
2018-11-29 12:12:15 +00:00
createPage({
path: slug,
component: getTemplateComponent(challengeType),
context: {
challengeMeta: {
superBlock,
block,
template,
required,
nextChallengePath: getNextChallengePath(node, index, thisArray),
prevChallengePath: getPrevChallengePath(node, index, thisArray),
id
},
slug
}
});
};
};
2018-11-29 12:12:15 +00:00
exports.createBlockIntroPages = function (createPage) {
return function (edge) {
const {
fields: { slug },
frontmatter: { block }
} = edge.node;
2018-11-29 12:12:15 +00:00
createPage({
path: slug,
component: intro,
context: {
block: dasherize(block),
slug
}
});
};
2018-11-29 12:12:15 +00:00
};
exports.createSuperBlockIntroPages = function (createPage) {
return function (edge) {
const {
fields: { slug },
frontmatter: { superBlock }
} = edge.node;
2018-11-29 12:12:15 +00:00
createPage({
path: slug,
component: superBlockIntro,
context: {
superBlock,
slug
}
});
};
2018-11-29 12:12:15 +00:00
};