Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last modified on each guide page #419

Merged
merged 7 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}