Skip to content

Commit

Permalink
feat: Populate edit url
Browse files Browse the repository at this point in the history
  • Loading branch information
timglaser committed Jun 18, 2020
1 parent ab6ff92 commit 88896b9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
8 changes: 7 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
allMdx(limit: 1000) {
edges {
node {
fileAbsolutePath
frontmatter {
path
template
Expand All @@ -28,7 +29,12 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
createPage({
path: node.frontmatter.path,
component: path.resolve(`src/templates/${node.frontmatter.template}.js`),
context: {}, // additional data can be passed via context
context: {
fileRelativePath: node.fileAbsolutePath.replace(
`${process.cwd()}/`,
''
),
},
});
});
};
19 changes: 13 additions & 6 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import FeatherIcon from './FeatherIcon';
import Logo from './Logo';
import PropTypes from 'prop-types';

const Footer = ({ className }) => (
const githubBaseUrl = 'https://github.com/newrelic/developer-website';

const Footer = ({ className, fileRelativePath }) => (
<footer className={cx(styles.footer, className)}>
<div className={cx('site-container', styles.container)}>
<div className={styles.left}>
Expand All @@ -24,11 +26,15 @@ const Footer = ({ className }) => (
</div>

<div className={styles.right}>
<Link to="/">
<FeatherIcon className={styles.linkIcon} name="edit" size="1rem" />
Edit this page
</Link>
<ExternalLink href="https://github.com/newrelic/developer-website/issues/new/choose">
{fileRelativePath && (
<ExternalLink
href={`${githubBaseUrl}/blob/master/${fileRelativePath}`}
>
<FeatherIcon className={styles.linkIcon} name="edit" size="1rem" />
Edit this page
</ExternalLink>
)}
<ExternalLink href={`${githubBaseUrl}/issues/new/choose`}>
<FeatherIcon className={styles.linkIcon} name="github" size="1rem" />
Create an issue
</ExternalLink>
Expand All @@ -39,6 +45,7 @@ const Footer = ({ className }) => (

Footer.propTypes = {
className: PropTypes.string,
fileRelativePath: PropTypes.string,
};

export default Footer;
4 changes: 3 additions & 1 deletion src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './Layout.module.scss';
import 'normalize.css';
import './styles.scss';

const Layout = ({ children }) => {
const Layout = ({ children, fileRelativePath }) => {
const [isMobileNavOpen, setIsMobileNavOpen] = useState(false);

return (
Expand All @@ -35,13 +35,15 @@ const Layout = ({ children }) => {
className={cx({
[styles.hideOnMobile]: isMobileNavOpen,
})}
fileRelativePath={fileRelativePath}
/>
</div>
);
};

Layout.propTypes = {
children: PropTypes.node.isRequired,
fileRelativePath: PropTypes.string,
};

export default Layout;
2 changes: 1 addition & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const guides = [
];

const IndexPage = () => (
<Layout>
<Layout fileRelativePath="src/pages/index.js">
<SEO />
<PageTitle>Observability for every developer</PageTitle>

Expand Down
5 changes: 3 additions & 2 deletions src/templates/GuideTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const components = {
code: (props) => <CodeSnippet {...props} />,
};

const GuideTemplate = ({ data }) => {
const GuideTemplate = ({ data, pageContext }) => {
const { mdx } = data;
const { frontmatter, body } = mdx;
const { title, description, duration } = frontmatter;
const crumbs = createBreadcrumbs(frontmatter.path, pages);

return (
<BreadcrumbContext.Provider value={crumbs}>
<Layout>
<Layout fileRelativePath={pageContext.fileRelativePath}>
<SEO title={title} description={description} />
<div className={styles.header}>
<PageTitle>{title}</PageTitle>
Expand All @@ -57,6 +57,7 @@ const GuideTemplate = ({ data }) => {

GuideTemplate.propTypes = {
data: PropTypes.object,
pageContext: PropTypes.shape({ fileRelativePath: PropTypes.string }),
};

export const pageQuery = graphql`
Expand Down

0 comments on commit 88896b9

Please sign in to comment.