diff --git a/client/gatsby-node.js b/client/gatsby-node.js
index 13fe801eee..b183365538 100644
--- a/client/gatsby-node.js
+++ b/client/gatsby-node.js
@@ -30,12 +30,15 @@ exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
}
if (node.internal.type === 'MarkdownRemark') {
- let slug = createFilePath({ node, getNode });
+ const slug = createFilePath({ node, getNode });
if (!slug.includes('LICENSE')) {
+ const {
+ frontmatter: { component = '' }
+ } = node;
createNodeField({ node, name: 'slug', value: slug });
+ createNodeField({ node, name: 'component', value: component });
}
}
-
};
exports.createPages = function createPages({ graphql, actions }) {
@@ -75,6 +78,7 @@ exports.createPages = function createPages({ graphql, actions }) {
fields {
slug
nodeIdentity
+ component
}
frontmatter {
block
diff --git a/client/src/templates/Guide/GuideArticle.js b/client/src/templates/Guide/GuideArticle.js
index 1f856b0d80..54c234155a 100644
--- a/client/src/templates/Guide/GuideArticle.js
+++ b/client/src/templates/Guide/GuideArticle.js
@@ -1,58 +1,28 @@
-import React, { Fragment } from 'react';
+import React from 'react';
import PropTypes from 'prop-types';
import { graphql } from 'gatsby';
-import Helmet from 'react-helmet';
-import Breadcrumbs from './components/Breadcrumbs';
+import ArticleLayout from './components/ArticleLayout';
const propTypes = {
- data: PropTypes.object,
- location: PropTypes.object,
- pageContext: PropTypes.shape({
- meta: PropTypes.objectOf(PropTypes.string)
- })
+ data: PropTypes.object
};
const GuideArticle = props => {
const {
- location: { pathname },
data: {
- markdownRemark: {
- html,
- fields: { slug },
- frontmatter: { title }
- }
- },
- pageContext: { meta }
+ markdownRemark: { html }
+ }
} = props;
return (
-
-
- {`${title} | freeCodeCamp Guide`}
-
-
-
-
-
-
-
-
+
-
+
);
};
@@ -65,12 +35,7 @@ export const pageQuery = graphql`
query ArticleById($id: String!) {
markdownRemark(id: { eq: $id }) {
html
- fields {
- slug
- }
- frontmatter {
- title
- }
+ ...ArticleLayout
}
}
`;
diff --git a/client/src/templates/Guide/components/ArticleLayout.js b/client/src/templates/Guide/components/ArticleLayout.js
new file mode 100644
index 0000000000..9f42aaf8e8
--- /dev/null
+++ b/client/src/templates/Guide/components/ArticleLayout.js
@@ -0,0 +1,69 @@
+import React, { Fragment } from 'react';
+import PropTypes from 'prop-types';
+import { graphql } from 'gatsby';
+import Helmet from 'react-helmet';
+
+import Breadcrumbs from './Breadcrumbs';
+
+const propTypes = {
+ children: PropTypes.any,
+ data: PropTypes.object,
+ location: PropTypes.object,
+ pageContext: PropTypes.shape({
+ meta: PropTypes.objectOf(PropTypes.string)
+ })
+};
+
+const ArticleLayout = props => {
+ const {
+ children,
+ location: { pathname },
+ data: {
+ markdownRemark: {
+ fields: { slug },
+ frontmatter: { title }
+ }
+ },
+ pageContext: { meta }
+ } = props;
+ return (
+
+
+ {`${title} | freeCodeCamp Guide`}
+
+
+
+
+
+
+
+
+ {children}
+
+ );
+};
+
+ArticleLayout.displayName = 'ArticleLayout';
+ArticleLayout.propTypes = propTypes;
+
+export default ArticleLayout;
+
+export const fragmentQuery = graphql`
+ fragment ArticleLayout on MarkdownRemark {
+ fields {
+ slug
+ }
+ frontmatter {
+ title
+ }
+ }
+`;
diff --git a/client/utils/gatsby/guidePageCreator.js b/client/utils/gatsby/guidePageCreator.js
index bebf6e3c21..85a21a14b2 100644
--- a/client/utils/gatsby/guidePageCreator.js
+++ b/client/utils/gatsby/guidePageCreator.js
@@ -13,7 +13,7 @@ exports.createGuideArticlePages = createPage => ({
node: {
htmlAst,
excerpt,
- fields: { slug },
+ fields: { slug, component },
id
}
}) => {
@@ -32,7 +32,13 @@ exports.createGuideArticlePages = createPage => ({
return createPage({
path: `/guide${slug}`,
- component: guideArticle,
+ component: !component
+ ? guideArticle
+ : path.resolve(
+ __dirname,
+ '../../src/templates/Guide/components/',
+ component
+ ),
context: {
id,
meta