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

179 lines
4.4 KiB
JavaScript
Raw Permalink Normal View History

2018-11-29 12:12:15 +00:00
const path = require('path');
const { dasherize } = require('../../../utils/slugs');
const { sortChallengeFiles } = require('../../../utils/sort-challengefiles');
const { challengeTypes, 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
);
feat: split rdbms into individual blocks and two challengeTypes (#44978) * feat: split english rdbms into individual blocks fix: stuff fix: remove from partiallyComplete array on submit fix: add suggestion Update client/i18n/locales/english/translations.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: prettier * fix: style suggestion * Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2022-02-11 09:39:27 -06: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,
feat: split rdbms into individual blocks and two challengeTypes (#44978) * feat: split english rdbms into individual blocks fix: stuff fix: remove from partiallyComplete array on submit fix: add suggestion Update client/i18n/locales/english/translations.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/i18n/locales/english/intro.json Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Update client/src/templates/Challenges/codeally/show.tsx Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: prettier * fix: style suggestion * Apply suggestions from code review Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2022-02-11 09:39:27 -06:00
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.challenge.fields.slug : '/learn';
}
function getPrevChallengePath(_node, index, nodeArray) {
const prev = nodeArray[index - 1];
return prev ? prev.node.challenge.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: { challenge } }, index, allChallengeEdges) {
const {
feat: enable new curriculum (#44183) * feat: use legacy flag chore: reorder challenges fix: linter revert: server change feat: unblock new editor fix: proper order fix: 0-based order fix: broke the order feat: move tribute certification to its own block feat: split the old projects block into 4 fix: put all blocks in order chore: add intro text refactor: use block, not blockName in query fix: project progress indicator * fix: reorder new challenges/certs * fix: reorder legacy challenges * fix: reintroduce legacy certs * feat: add showNewCurriculum flag to env * chore: forgot sample.env * feat: use feature flag for display * fix: rename meta + dirs to match new blocks * fix: add new blocks to help-category-map * fix: update completion-modal for new GQL schema * test: duplicate title/id errors -> warnings * fix: update completion-modal to new GQL schema Mk2 * chore: re-order metas (again) * fix: revert super-block-intro changes The intro needs to show both legacy and new content. We need to decide which pages are created, rather than than what a page shows when rendered. * feat: move upcoming curriculum into own superblock * fix: handle one certification with two superBlocks * fix: remove duplicated intros * fix: remove duplicate projects from /settings * fix: drop 'two' from Responsive Web Design Two * chore: rename slug suffix from two to v2 * feat: control display of new curriculum * feat: control project paths shown on /settings * fix: use new project order for /settings This does mean that /settings will change before the release, but I don't think it's serious. All the projects are there, just not in the legacy order. * fix: claim/show cert button * chore: remove isLegacy Since we have legacy superblocks, we don't currently need individual blocks to be legacy * test: fix utils.test * fix: verifyCanClaim needs certification If Shaun removes the cert claim cards, maybe we can remove this entirely * fix: add hasEditableBoundaries flags where needed * chore: remove isUpcomingChange * chore: v2 -> 22 Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-12-20 10:36:31 -08:00
certification,
superBlock,
block,
fields: { slug },
required = [],
template,
challengeType,
id
} = challenge;
// 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: {
feat: enable new curriculum (#44183) * feat: use legacy flag chore: reorder challenges fix: linter revert: server change feat: unblock new editor fix: proper order fix: 0-based order fix: broke the order feat: move tribute certification to its own block feat: split the old projects block into 4 fix: put all blocks in order chore: add intro text refactor: use block, not blockName in query fix: project progress indicator * fix: reorder new challenges/certs * fix: reorder legacy challenges * fix: reintroduce legacy certs * feat: add showNewCurriculum flag to env * chore: forgot sample.env * feat: use feature flag for display * fix: rename meta + dirs to match new blocks * fix: add new blocks to help-category-map * fix: update completion-modal for new GQL schema * test: duplicate title/id errors -> warnings * fix: update completion-modal to new GQL schema Mk2 * chore: re-order metas (again) * fix: revert super-block-intro changes The intro needs to show both legacy and new content. We need to decide which pages are created, rather than than what a page shows when rendered. * feat: move upcoming curriculum into own superblock * fix: handle one certification with two superBlocks * fix: remove duplicated intros * fix: remove duplicate projects from /settings * fix: drop 'two' from Responsive Web Design Two * chore: rename slug suffix from two to v2 * feat: control display of new curriculum * feat: control project paths shown on /settings * fix: use new project order for /settings This does mean that /settings will change before the release, but I don't think it's serious. All the projects are there, just not in the legacy order. * fix: claim/show cert button * chore: remove isLegacy Since we have legacy superblocks, we don't currently need individual blocks to be legacy * test: fix utils.test * fix: verifyCanClaim needs certification If Shaun removes the cert claim cards, maybe we can remove this entirely * fix: add hasEditableBoundaries flags where needed * chore: remove isUpcomingChange * chore: v2 -> 22 Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-12-20 10:36:31 -08:00
certification,
superBlock,
block,
template,
required,
nextChallengePath: getNextChallengePath(
challenge,
index,
allChallengeEdges
),
prevChallengePath: getPrevChallengePath(
challenge,
index,
allChallengeEdges
),
id
},
projectPreview: getProjectPreviewConfig(challenge, allChallengeEdges),
slug
}
});
};
};
2018-11-29 12:12:15 +00:00
function getProjectPreviewConfig(challenge, allChallengeEdges) {
const { block, challengeOrder, challengeType, usesMultifileEditor } =
challenge;
const challengesInBlock = allChallengeEdges
.filter(({ node: { challenge } }) => challenge.block === block)
.map(({ node: { challenge } }) => challenge);
const lastChallenge = challengesInBlock[challengesInBlock.length - 1];
const solutionToLastChallenge = sortChallengeFiles(
lastChallenge.solutions[0] ?? []
);
const lastChallengeFiles = sortChallengeFiles(
lastChallenge.challengeFiles ?? []
);
const projectPreviewChallengeFiles = lastChallengeFiles.map((file, id) => ({
...file,
contents: solutionToLastChallenge[id]?.contents ?? file.contents
}));
return {
showProjectPreview:
challengeOrder === 0 &&
usesMultifileEditor &&
challengeType !== challengeTypes.multiFileCertProject,
challengeData: {
challengeType: lastChallenge.challengeType,
challengeFiles: projectPreviewChallengeFiles
}
};
}
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 },
feat: enable new curriculum (#44183) * feat: use legacy flag chore: reorder challenges fix: linter revert: server change feat: unblock new editor fix: proper order fix: 0-based order fix: broke the order feat: move tribute certification to its own block feat: split the old projects block into 4 fix: put all blocks in order chore: add intro text refactor: use block, not blockName in query fix: project progress indicator * fix: reorder new challenges/certs * fix: reorder legacy challenges * fix: reintroduce legacy certs * feat: add showNewCurriculum flag to env * chore: forgot sample.env * feat: use feature flag for display * fix: rename meta + dirs to match new blocks * fix: add new blocks to help-category-map * fix: update completion-modal for new GQL schema * test: duplicate title/id errors -> warnings * fix: update completion-modal to new GQL schema Mk2 * chore: re-order metas (again) * fix: revert super-block-intro changes The intro needs to show both legacy and new content. We need to decide which pages are created, rather than than what a page shows when rendered. * feat: move upcoming curriculum into own superblock * fix: handle one certification with two superBlocks * fix: remove duplicated intros * fix: remove duplicate projects from /settings * fix: drop 'two' from Responsive Web Design Two * chore: rename slug suffix from two to v2 * feat: control display of new curriculum * feat: control project paths shown on /settings * fix: use new project order for /settings This does mean that /settings will change before the release, but I don't think it's serious. All the projects are there, just not in the legacy order. * fix: claim/show cert button * chore: remove isLegacy Since we have legacy superblocks, we don't currently need individual blocks to be legacy * test: fix utils.test * fix: verifyCanClaim needs certification If Shaun removes the cert claim cards, maybe we can remove this entirely * fix: add hasEditableBoundaries flags where needed * chore: remove isUpcomingChange * chore: v2 -> 22 Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-12-20 10:36:31 -08:00
frontmatter: { superBlock, certification }
} = edge.node;
2018-11-29 12:12:15 +00:00
feat: enable new curriculum (#44183) * feat: use legacy flag chore: reorder challenges fix: linter revert: server change feat: unblock new editor fix: proper order fix: 0-based order fix: broke the order feat: move tribute certification to its own block feat: split the old projects block into 4 fix: put all blocks in order chore: add intro text refactor: use block, not blockName in query fix: project progress indicator * fix: reorder new challenges/certs * fix: reorder legacy challenges * fix: reintroduce legacy certs * feat: add showNewCurriculum flag to env * chore: forgot sample.env * feat: use feature flag for display * fix: rename meta + dirs to match new blocks * fix: add new blocks to help-category-map * fix: update completion-modal for new GQL schema * test: duplicate title/id errors -> warnings * fix: update completion-modal to new GQL schema Mk2 * chore: re-order metas (again) * fix: revert super-block-intro changes The intro needs to show both legacy and new content. We need to decide which pages are created, rather than than what a page shows when rendered. * feat: move upcoming curriculum into own superblock * fix: handle one certification with two superBlocks * fix: remove duplicated intros * fix: remove duplicate projects from /settings * fix: drop 'two' from Responsive Web Design Two * chore: rename slug suffix from two to v2 * feat: control display of new curriculum * feat: control project paths shown on /settings * fix: use new project order for /settings This does mean that /settings will change before the release, but I don't think it's serious. All the projects are there, just not in the legacy order. * fix: claim/show cert button * chore: remove isLegacy Since we have legacy superblocks, we don't currently need individual blocks to be legacy * test: fix utils.test * fix: verifyCanClaim needs certification If Shaun removes the cert claim cards, maybe we can remove this entirely * fix: add hasEditableBoundaries flags where needed * chore: remove isUpcomingChange * chore: v2 -> 22 Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-12-20 10:36:31 -08:00
if (!certification) {
throw Error(
`superBlockIntro page, '${superBlock}' must have certification in frontmatter`
);
}
// TODO: throw if it encounters an unknown certification. Also, handle
// coding-interview-prep. it's not a certification, but it is a superBlock.
createPage({
path: slug,
component: superBlockIntro,
context: {
feat: enable new curriculum (#44183) * feat: use legacy flag chore: reorder challenges fix: linter revert: server change feat: unblock new editor fix: proper order fix: 0-based order fix: broke the order feat: move tribute certification to its own block feat: split the old projects block into 4 fix: put all blocks in order chore: add intro text refactor: use block, not blockName in query fix: project progress indicator * fix: reorder new challenges/certs * fix: reorder legacy challenges * fix: reintroduce legacy certs * feat: add showNewCurriculum flag to env * chore: forgot sample.env * feat: use feature flag for display * fix: rename meta + dirs to match new blocks * fix: add new blocks to help-category-map * fix: update completion-modal for new GQL schema * test: duplicate title/id errors -> warnings * fix: update completion-modal to new GQL schema Mk2 * chore: re-order metas (again) * fix: revert super-block-intro changes The intro needs to show both legacy and new content. We need to decide which pages are created, rather than than what a page shows when rendered. * feat: move upcoming curriculum into own superblock * fix: handle one certification with two superBlocks * fix: remove duplicated intros * fix: remove duplicate projects from /settings * fix: drop 'two' from Responsive Web Design Two * chore: rename slug suffix from two to v2 * feat: control display of new curriculum * feat: control project paths shown on /settings * fix: use new project order for /settings This does mean that /settings will change before the release, but I don't think it's serious. All the projects are there, just not in the legacy order. * fix: claim/show cert button * chore: remove isLegacy Since we have legacy superblocks, we don't currently need individual blocks to be legacy * test: fix utils.test * fix: verifyCanClaim needs certification If Shaun removes the cert claim cards, maybe we can remove this entirely * fix: add hasEditableBoundaries flags where needed * chore: remove isUpcomingChange * chore: v2 -> 22 Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-12-20 10:36:31 -08:00
certification,
superBlock,
slug
}
});
};
2018-11-29 12:12:15 +00:00
};