Add Intro pages through markdown
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
dcb6378975
commit
ca6748a477
@ -9,6 +9,7 @@ const classic = path.resolve(
|
||||
__dirname,
|
||||
'./src/templates/Challenges/classic/Show.js'
|
||||
);
|
||||
const intro = path.resolve(__dirname, './src/templates/Introduction/Intro.js');
|
||||
|
||||
const views = {
|
||||
// backend: BackEnd,
|
||||
@ -33,6 +34,16 @@ exports.onCreateNode = function onCreateNode({ node, boundActionCreators }) {
|
||||
// TODO: Normalise tests to { test: '', testString: ''}?
|
||||
createNodeField({ node, name: 'tests', value: tests });
|
||||
}
|
||||
|
||||
if (node.internal.type === 'MarkdownRemark') {
|
||||
const { frontmatter: { block, superBlock, title } } = node;
|
||||
|
||||
const slug = `/${dasherize(superBlock)}${
|
||||
block ? `/${dasherize(block)}${title ? `/${dasherize(title)}` : ''}` : ''
|
||||
}`;
|
||||
|
||||
createNodeField({ node, name: 'slug', value: slug });
|
||||
}
|
||||
};
|
||||
|
||||
exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||
@ -60,6 +71,21 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
allMarkdownRemark {
|
||||
edges {
|
||||
node {
|
||||
fields {
|
||||
slug
|
||||
}
|
||||
frontmatter {
|
||||
block
|
||||
superBlock
|
||||
title
|
||||
}
|
||||
html
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`).then(result => {
|
||||
if (result.errors) {
|
||||
@ -93,6 +119,18 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Create intro pages
|
||||
result.data.allMarkdownRemark.edges.forEach(edge => {
|
||||
const { fields: { slug } } = edge.node;
|
||||
createPage({
|
||||
path: slug,
|
||||
component: intro,
|
||||
context: {
|
||||
slug
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user