Skip to content

Commit

Permalink
Merge pull request #419 from newrelic/cayla/last-updated
Browse files Browse the repository at this point in the history
Last modified on each guide page
  • Loading branch information
caylahamann authored Jul 10, 2020
2 parents 28a3999 + 45e54a0 commit 5611251
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require(`path`);
const { execSync } = require('child_process');

const getFileRelativePath = (absolutePath) =>
absolutePath.replace(`${process.cwd()}/`, '');
Expand Down Expand Up @@ -59,6 +60,17 @@ exports.createPages = async ({ actions, graphql, reporter }) => {

exports.onCreateNode = ({ node, actions }) => {
// if we don't have a relative path, attempt to get one
if (node.internal.type === 'Mdx' && node.fileAbsolutePath) {
const gitAuthorTime = execSync(
`git log -1 --pretty=format:%aI ${node.fileAbsolutePath}`
).toString();
actions.createNodeField({
node,
name: 'gitAuthorTime',
value: gitAuthorTime,
});
}

if (node.context && !node.context.fileRelativePath) {
const { createPage } = actions;
const { path, component } = node;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

.content {
flex: 1;
margin-bottom: 2rem;
}

.footer {
border-top: 1px solid var(--divider-color);
padding-top: 2rem;
margin-top: 4rem;
}

.hideOnDesktop {
Expand Down
8 changes: 7 additions & 1 deletion src/templates/GuideTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import styles from './GuideTemplate.module.scss';

const GuideTemplate = ({ data }) => {
const { mdx } = data;
const { frontmatter, body } = mdx;
const { frontmatter, body, fields } = mdx;
const { title, description, duration } = frontmatter;

return (
Expand All @@ -27,6 +27,9 @@ const GuideTemplate = ({ data }) => {
)}
</div>
<MDXContainer>{body}</MDXContainer>
<div className={styles.lastUpdated}>
{`Page last modified on ${fields.gitAuthorTime}`}
</div>
</Layout>
);
};
Expand All @@ -45,6 +48,9 @@ export const pageQuery = graphql`
title
description
}
fields {
gitAuthorTime(formatString: "MMMM DD, YYYY")
}
}
}
`;
Expand Down
9 changes: 9 additions & 0 deletions src/templates/GuideTemplate.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@
.clock {
margin-right: 0.25rem;
}

.lastUpdated {
display: flex;
flex-direction: row;
justify-content: flex-end;
font-size: 0.875rem;
font-style: italic;
margin-top: 4rem;
}

0 comments on commit 5611251

Please sign in to comment.