2018-11-29 12:12:15 +00:00
|
|
|
const path = require('path');
|
2019-09-25 20:16:08 +02:00
|
|
|
const { dasherize } = require('../../../utils/slugs');
|
2018-11-29 12:12:15 +00:00
|
|
|
|
|
|
|
const { viewTypes } = require('../challengeTypes');
|
|
|
|
|
|
|
|
const backend = path.resolve(
|
|
|
|
__dirname,
|
2019-09-19 12:44:58 +05:30
|
|
|
'../../src/templates/Challenges/projects/backend/Show.js'
|
2018-11-29 12:12:15 +00:00
|
|
|
);
|
|
|
|
const classic = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../src/templates/Challenges/classic/Show.js'
|
|
|
|
);
|
2019-09-19 12:44:58 +05:30
|
|
|
const frontend = path.resolve(
|
2018-11-29 12:12:15 +00:00
|
|
|
__dirname,
|
2019-09-19 12:44:58 +05:30
|
|
|
'../../src/templates/Challenges/projects/frontend/Show.js'
|
2018-11-29 12:12:15 +00:00
|
|
|
);
|
|
|
|
const intro = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../src/templates/Introduction/Intro.js'
|
|
|
|
);
|
|
|
|
const superBlockIntro = path.resolve(
|
|
|
|
__dirname,
|
|
|
|
'../../src/templates/Introduction/SuperBlockIntro.js'
|
|
|
|
);
|
|
|
|
|
|
|
|
const views = {
|
|
|
|
backend,
|
|
|
|
classic,
|
|
|
|
modern: classic,
|
2019-09-19 12:44:58 +05:30
|
|
|
frontend
|
2018-11-29 12:12:15 +00:00
|
|
|
// quiz: Quiz
|
|
|
|
};
|
|
|
|
|
|
|
|
const getNextChallengePath = (node, index, nodeArray) => {
|
|
|
|
const next = nodeArray[index + 1];
|
2019-07-18 04:46:00 -05:00
|
|
|
return next ? next.node.fields.slug : '/learn';
|
2018-11-29 12:12:15 +00:00
|
|
|
};
|
2019-07-18 04:46:00 -05:00
|
|
|
|
|
|
|
const getPrevChallengePath = (node, index, nodeArray) => {
|
|
|
|
const prev = nodeArray[index - 1];
|
|
|
|
return prev ? prev.node.fields.slug : '/learn';
|
|
|
|
};
|
|
|
|
|
2018-11-29 12:12:15 +00:00
|
|
|
const getTemplateComponent = challengeType => views[viewTypes[challengeType]];
|
|
|
|
|
|
|
|
const getIntroIfRequired = (node, index, nodeArray) => {
|
|
|
|
const next = nodeArray[index + 1];
|
|
|
|
const isEndOfBlock = next && next.node.challengeOrder === 0;
|
|
|
|
let nextSuperBlock = '';
|
|
|
|
let nextBlock = '';
|
|
|
|
if (next) {
|
|
|
|
const { superBlock, block } = next.node;
|
|
|
|
nextSuperBlock = superBlock;
|
|
|
|
nextBlock = block;
|
|
|
|
}
|
|
|
|
return isEndOfBlock
|
|
|
|
? `/learn/${dasherize(nextSuperBlock)}/${dasherize(nextBlock)}`
|
|
|
|
: '';
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.createChallengePages = createPage => ({ node }, index, thisArray) => {
|
|
|
|
const {
|
2020-02-04 06:03:56 +01:00
|
|
|
superBlock,
|
2019-11-15 11:33:08 -06:00
|
|
|
block,
|
2018-11-29 12:12:15 +00:00
|
|
|
fields: { slug },
|
|
|
|
required = [],
|
|
|
|
template,
|
|
|
|
challengeType,
|
|
|
|
id
|
|
|
|
} = node;
|
|
|
|
if (challengeType === 7) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return createPage({
|
|
|
|
path: slug,
|
|
|
|
component: getTemplateComponent(challengeType),
|
|
|
|
context: {
|
|
|
|
challengeMeta: {
|
2020-02-04 06:03:56 +01:00
|
|
|
superBlock,
|
2019-11-15 11:33:08 -06:00
|
|
|
block: block,
|
2018-11-29 12:12:15 +00:00
|
|
|
introPath: getIntroIfRequired(node, index, thisArray),
|
|
|
|
template,
|
|
|
|
required,
|
|
|
|
nextChallengePath: getNextChallengePath(node, index, thisArray),
|
2019-07-18 04:46:00 -05:00
|
|
|
prevChallengePath: getPrevChallengePath(node, index, thisArray),
|
2018-11-29 12:12:15 +00:00
|
|
|
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: dasherize(superBlock),
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|