initial commit

This commit is contained in:
Stuart Taylor
2018-04-06 14:51:52 +01:00
committed by Mrugesh Mohapatra
parent 1314830576
commit 15aae9a57c
146 changed files with 44507 additions and 8380 deletions

View File

@ -1,7 +1,86 @@
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require('path');
const { dasherize } = require('./utils');
const { viewTypes } = require('./utils/challengeTypes');
const { blockNameify } = require('./utils/blockNameify');
// You can delete this file if you're not using it
const views = {
// backend: BackEnd,
classic: path.resolve(
__dirname,
'./src/templates/Challenges/views/classic/Show.js'
),
// modern: Modern,
project: path.resolve(
__dirname,
'./src/templates/Challenges/views/project/Show.js'
),
// quiz: Quiz,
// simple: Project,
step: path.resolve(__dirname, './src/templates/Challenges/views/step/Show.js')
// invalid: NotFound
};
exports.onCreateNode = function onCreateNode({ node, boundActionCreators }) {
const { createNodeField } = boundActionCreators;
if (node.internal.type === 'ChallengeNode') {
const { tests = [], block, title, superBlock } = node;
const slug = `/${dasherize(superBlock)}/${dasherize(block)}/${dasherize(
title
)}`;
createNodeField({ node, name: 'slug', value: slug });
createNodeField({ node, name: 'blockName', value: blockNameify(block) });
// TODO: Normalise tests to { test: '', testString: ''}?
createNodeField({ node, name: 'tests', value: tests });
}
};
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
// Query for all markdown "nodes" and for the slug we previously created.
resolve(
graphql(`
{
allChallengeNode(sort: { fields: [superOrder, order, suborder] }) {
edges {
node {
challengeType
id
fields {
slug
}
}
}
}
}
`).then(result => {
if (result.errors) {
console.log(result.errors);
reject(result.errors);
}
// Create challenge pages.
result.data.allChallengeNode.edges.forEach((edge, index, thisArray) => {
const { fields: { slug }, challengeType, id } = edge.node;
const next = thisArray[index + 1];
const nextChallengePath = next ? next.node.fields.slug : '/';
createPage({
path: slug,
component: views[viewTypes[challengeType]],
context: {
challengeMeta: {
nextChallengePath,
id
},
slug
}
});
});
return;
})
);
});
};