feat(guide): add footer link to article source on GitHub
fix/suggested-changes
This commit is contained in:
@ -4,6 +4,7 @@ const { createFilePath } = require('gatsby-source-filesystem');
|
|||||||
|
|
||||||
const { dasherize } = require('./utils');
|
const { dasherize } = require('./utils');
|
||||||
const { blockNameify } = require('./utils/blockNameify');
|
const { blockNameify } = require('./utils/blockNameify');
|
||||||
|
const { getGithubPath } = require('./utils/getGithubPath');
|
||||||
const {
|
const {
|
||||||
createChallengePages,
|
createChallengePages,
|
||||||
createBlockIntroPages,
|
createBlockIntroPages,
|
||||||
@ -33,10 +34,16 @@ exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
|
|||||||
const slug = createFilePath({ node, getNode });
|
const slug = createFilePath({ node, getNode });
|
||||||
if (!slug.includes('LICENSE')) {
|
if (!slug.includes('LICENSE')) {
|
||||||
const {
|
const {
|
||||||
|
fileAbsolutePath,
|
||||||
frontmatter: { component = '' }
|
frontmatter: { component = '' }
|
||||||
} = node;
|
} = node;
|
||||||
createNodeField({ node, name: 'slug', value: slug });
|
createNodeField({ node, name: 'slug', value: slug });
|
||||||
createNodeField({ node, name: 'component', value: component });
|
createNodeField({ node, name: 'component', value: component });
|
||||||
|
createNodeField({
|
||||||
|
node,
|
||||||
|
name: 'githubPath',
|
||||||
|
value: getGithubPath(fileAbsolutePath)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -79,6 +86,7 @@ exports.createPages = function createPages({ graphql, actions }) {
|
|||||||
slug
|
slug
|
||||||
nodeIdentity
|
nodeIdentity
|
||||||
component
|
component
|
||||||
|
githubPath
|
||||||
}
|
}
|
||||||
frontmatter {
|
frontmatter {
|
||||||
block
|
block
|
||||||
|
@ -4,6 +4,7 @@ import { graphql } from 'gatsby';
|
|||||||
import Helmet from 'react-helmet';
|
import Helmet from 'react-helmet';
|
||||||
|
|
||||||
import Breadcrumbs from './Breadcrumbs';
|
import Breadcrumbs from './Breadcrumbs';
|
||||||
|
import GuideFooter from './GuideFooter';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
@ -20,7 +21,7 @@ const ArticleLayout = props => {
|
|||||||
location: { pathname },
|
location: { pathname },
|
||||||
data: {
|
data: {
|
||||||
markdownRemark: {
|
markdownRemark: {
|
||||||
fields: { slug },
|
fields: { slug, githubPath },
|
||||||
frontmatter: { title }
|
frontmatter: { title }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -48,6 +49,7 @@ const ArticleLayout = props => {
|
|||||||
</Helmet>
|
</Helmet>
|
||||||
<Breadcrumbs path={pathname} />
|
<Breadcrumbs path={pathname} />
|
||||||
{children}
|
{children}
|
||||||
|
<GuideFooter githubPath={githubPath} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -61,6 +63,7 @@ export const fragmentQuery = graphql`
|
|||||||
fragment ArticleLayout on MarkdownRemark {
|
fragment ArticleLayout on MarkdownRemark {
|
||||||
fields {
|
fields {
|
||||||
slug
|
slug
|
||||||
|
githubPath
|
||||||
}
|
}
|
||||||
frontmatter {
|
frontmatter {
|
||||||
title
|
title
|
||||||
|
39
client/src/templates/Guide/components/GuideFooter.js
Normal file
39
client/src/templates/Guide/components/GuideFooter.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Link, Spacer } from '../../../components/helpers';
|
||||||
|
|
||||||
|
const propTypes = {
|
||||||
|
githubPath: PropTypes.string
|
||||||
|
};
|
||||||
|
const GuideFooter = props => {
|
||||||
|
const { githubPath } = props;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Spacer />
|
||||||
|
<hr />
|
||||||
|
<h4>Contributing to the Guide</h4>
|
||||||
|
<p>
|
||||||
|
This open source guide is curated by thousands of contributors. You can
|
||||||
|
help by researching, writing and updating these articles. It is an easy
|
||||||
|
and fun way to get started with contributing to open source.
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<Link to='https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md#research-write-and-update-our-guide-articles'>
|
||||||
|
Follow our contributing guidelines for working on guide articles
|
||||||
|
</Link>
|
||||||
|
.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<Link to={githubPath}>Edit this article on GitHub</Link>.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<Spacer />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GuideFooter.displayName = 'GuideFooter';
|
||||||
|
GuideFooter.propTypes = propTypes;
|
||||||
|
|
||||||
|
export default GuideFooter;
|
12
client/utils/getGithubPath.js
Normal file
12
client/utils/getGithubPath.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
exports.getGithubPath = function getGithubPath(fileAbsolutePath) {
|
||||||
|
const { NODE_ENV: env } = process.env;
|
||||||
|
const guideType = env === 'production' ? 'guide' : 'mock-guide';
|
||||||
|
let githubFilePath =
|
||||||
|
'https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md#research-write-and-update-our-guide-articles';
|
||||||
|
const pathIndex = fileAbsolutePath.indexOf(`/${guideType}`);
|
||||||
|
if (pathIndex > -1) {
|
||||||
|
const newPath = fileAbsolutePath.slice(pathIndex);
|
||||||
|
githubFilePath = `https://github.com/freeCodeCamp/freeCodeCamp/blob/master${newPath}`;
|
||||||
|
}
|
||||||
|
return githubFilePath;
|
||||||
|
};
|
Reference in New Issue
Block a user