From 1f7b2d5071846c5a131bbd1d9cbff2d1e14775e7 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 29 Jul 2020 16:33:09 -0700 Subject: [PATCH] feat: move the related content area to the guide template --- gatsby-node.js | 3 --- src/components/RelatedContent.js | 30 ++++++++++++++++++++++-- src/layouts/MainLayout.js | 39 +++++--------------------------- src/templates/GuideTemplate.js | 30 ++++++++++++++++++++---- 4 files changed, 60 insertions(+), 42 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index a9af1f459..dab0520d6 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -4,8 +4,6 @@ const { execSync } = require('child_process'); const getFileRelativePath = (absolutePath) => absolutePath.replace(`${process.cwd()}/`, ''); -const camelize = (str) => str[0].toLowerCase() + str.slice(1); - exports.createPages = async ({ actions, graphql, reporter }) => { const { createPage, createRedirect } = actions; @@ -51,7 +49,6 @@ exports.createPages = async ({ actions, graphql, reporter }) => { component: path.resolve(`src/templates/${frontmatter.template}.js`), context: { fileRelativePath: getFileRelativePath(node.fileAbsolutePath), - pageType: camelize(frontmatter.template).replace('Template', ''), guidesFilter: frontmatter.template === 'OverviewTemplate' ? `${frontmatter.path}/*` diff --git a/src/components/RelatedContent.js b/src/components/RelatedContent.js index 9f0b7edbd..2fc8a3d1d 100644 --- a/src/components/RelatedContent.js +++ b/src/components/RelatedContent.js @@ -5,7 +5,10 @@ import { graphql, useStaticQuery } from 'gatsby'; import { Button, ExternalLink, Icon } from '@newrelic/gatsby-theme-newrelic'; import { PageContext } from './PageContext'; -const RelatedContent = ({ className }) => { +const RelatedContent = ({ className, page }) => { + const { + fields: { gitAuthorTime }, + } = page; const { site } = useStaticQuery(graphql` query { site { @@ -44,7 +47,7 @@ const RelatedContent = ({ className }) => { + +
+ {`Page last modified on ${gitAuthorTime}`} +
); }; @@ -63,4 +81,12 @@ RelatedContent.propTypes = { className: PropTypes.string, }; +export const query = graphql` + fragment RelatedContent_page on Mdx { + fields { + gitAuthorTime(formatString: "MMMM DD, YYYY") + } + } +`; + export default RelatedContent; diff --git a/src/layouts/MainLayout.js b/src/layouts/MainLayout.js index 315539852..03b7e879b 100644 --- a/src/layouts/MainLayout.js +++ b/src/layouts/MainLayout.js @@ -10,30 +10,12 @@ import Footer from '../components/Footer'; import MobileHeader from '../components/MobileHeader'; import Sidebar from '../components/Sidebar'; import CookieApprovalDialog from '../components/CookieApprovalDialog'; -import RelatedContent from '../components/RelatedContent'; import '../components/styles.scss'; import usePageContext from '../hooks/usePageContext'; const gaTrackingId = 'UA-3047412-33'; const gdprConsentCookieName = 'newrelic-gdpr-consent'; -const RELATED_CONTENT_PAGE_TYPES = ['guide']; - -const GRID_LAYOUTS = { - relatedContent: css` - grid-template-areas: - 'sidebar content related-content' - 'sidebar footer footer'; - grid-template-columns: var(--sidebar-width) minmax(0, 1fr) 340px; - `, - default: css` - grid-template-areas: - 'sidebar content' - 'sidebar footer'; - grid-template-columns: var(--sidebar-width) minmax(0, 1fr); - `, -}; - const MainLayout = ({ children }) => { const { site: { layout, siteMetadata }, @@ -51,7 +33,7 @@ const MainLayout = ({ children }) => { } `); - const { fileRelativePath, pageType } = usePageContext(); + const { fileRelativePath } = usePageContext(); const [cookieConsent, setCookieConsent] = useState(false); const [isMobileNavOpen, setIsMobileNavOpen] = useState(false); const isComponentDoc = fileRelativePath.includes( @@ -104,15 +86,15 @@ const MainLayout = ({ children }) => {
{ css={css` grid-area: content; padding: ${layout.contentPadding} 0; + padding-right: ${layout.contentPadding}; `} > {children} - {RELATED_CONTENT_PAGE_TYPES.includes(pageType) && ( - - )}