feat(guide): Import guide in to the client app

This commit is contained in:
Bouncey
2018-10-04 14:47:55 +01:00
committed by Stuart Taylor
parent 2723a943c9
commit 6e728ce16d
4338 changed files with 148283 additions and 4200 deletions

View File

@ -1,6 +1,9 @@
const { dasherize } = require('..');
const path = require('path');
const select = require('unist-util-select');
const { head } = require('lodash');
const { dasherize } = require('..');
const { isAStubRE } = require('../regEx');
const { viewTypes } = require('../challengeTypes');
@ -25,6 +28,11 @@ const superBlockIntro = path.resolve(
'../../src/templates/Introduction/SuperBlockIntro.js'
);
const guideArticle = path.resolve(
__dirname,
'../../src/templates/Guide/GuideArticle.js'
);
const views = {
backend,
classic,
@ -41,7 +49,7 @@ const getTemplateComponent = challengeType => views[viewTypes[challengeType]];
const getIntroIfRequired = (node, index, nodeArray) => {
const next = nodeArray[index + 1];
const isEndOfBlock = next && next.node.suborder === 1;
const isEndOfBlock = next && next.node.challengeOrder === 1;
let nextSuperBlock = '';
let nextBlock = '';
if (next) {
@ -55,7 +63,13 @@ const getIntroIfRequired = (node, index, nodeArray) => {
};
exports.createChallengePages = createPage => ({ node }, index, thisArray) => {
const { fields: { slug }, required = [], template, challengeType, id } = node;
const {
fields: { slug },
required = [],
template,
challengeType,
id
} = node;
if (challengeType === 7) {
return;
}
@ -76,28 +90,65 @@ exports.createChallengePages = createPage => ({ node }, index, thisArray) => {
});
};
exports.createIntroPages = createPage => edge => {
const { fields: { slug }, frontmatter: { superBlock, block } } = edge.node;
exports.createBlockIntroPages = createPage => edge => {
const {
fields: { slug },
frontmatter: { block }
} = edge.node;
// If there is no block specified in the markdown we assume the markdown is
// for a superblock introduction. Otherwise create a block intro page.
if (!block) {
createPage({
path: slug,
component: superBlockIntro,
context: {
superBlock: dasherize(superBlock),
slug
}
});
} else {
createPage({
path: slug,
component: intro,
context: {
block: dasherize(block),
slug
}
});
}
createPage({
path: slug,
component: intro,
context: {
block: dasherize(block),
slug
}
});
};
exports.createSuperBlockIntroPages = createPage => edge => {
const {
fields: { slug },
frontmatter: { superBlock }
} = edge.node;
createPage({
path: slug,
component: superBlockIntro,
context: {
superBlock: dasherize(superBlock),
slug
}
});
};
exports.createGuideArticlePages = createPage => ({
node: {
htmlAst,
excerpt,
fields: { slug },
id
}
}) => {
let meta = {};
if (!isAStubRE.test(excerpt)) {
const featureImage = head(select(htmlAst, 'element[tagName=img]'));
meta.featureImage = featureImage
? featureImage.properties.src
: 'https://s3.amazonaws.com/freecodecamp' +
'/reecodecamp-square-logo-large.jpg';
const description = head(select(htmlAst, 'element[tagName=p]'));
meta.description = description ? description.children[0].value : '';
}
createPage({
path: slug,
component: guideArticle,
context: {
id,
meta
}
});
};