From fdd265ecfff817dba951cdbfffc422779bd5dc0e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 13 Aug 2020 10:37:12 -0700 Subject: [PATCH] feat: add related resources from swiftype to the right rail --- gatsby-node.js | 9 +++++++++ .../RelatedContentModules/Resources.js | 16 +++++++++++++--- src/templates/GuideTemplate.js | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index dab0520d6..5d4fc0ed9 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -1,6 +1,8 @@ const path = require(`path`); const { execSync } = require('child_process'); +const MAX_RESULTS = 5; + const getFileRelativePath = (absolutePath) => absolutePath.replace(`${process.cwd()}/`, ''); @@ -17,6 +19,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => { path template redirects + resources { + url + } } } } @@ -53,6 +58,10 @@ exports.createPages = async ({ actions, graphql, reporter }) => { frontmatter.template === 'OverviewTemplate' ? `${frontmatter.path}/*` : undefined, + relatedResourceLimit: Math.max( + MAX_RESULTS - (frontmatter.resources || []).length, + 0 + ), }, }); }); diff --git a/src/components/RelatedContentModules/Resources.js b/src/components/RelatedContentModules/Resources.js index cbdb9eeae..aeea1806c 100644 --- a/src/components/RelatedContentModules/Resources.js +++ b/src/components/RelatedContentModules/Resources.js @@ -15,6 +15,7 @@ const SITE_TAGS = { kubernetes: 'https://kubernetes.io', youtube: 'https://youtube.com', discuss: 'https://discuss.newrelic.com', + 'newrelic.com': 'https://newrelic.com', }; const findTag = (resource) => @@ -29,10 +30,11 @@ const normalizeDeveloperUrl = (url) => const Resources = ({ page }) => { const { + relatedResources, frontmatter: { resources }, } = page; - return resources?.length > 0 ? ( + return (
Related resources
- ) : null; + ); }; Resources.propTypes = { @@ -111,6 +113,10 @@ Resources.propTypes = { }) ), }).isRequired, + relatedResources: PropTypes.shape({ + title: PropTypes.string, + url: PropTypes.string, + }), }).isRequired, }; @@ -122,6 +128,10 @@ export const query = graphql` url } } + relatedResources(limit: $relatedResourceLimit) { + title + url + } } `; diff --git a/src/templates/GuideTemplate.js b/src/templates/GuideTemplate.js index e6a6dff7f..e7ab0bf29 100644 --- a/src/templates/GuideTemplate.js +++ b/src/templates/GuideTemplate.js @@ -56,7 +56,7 @@ GuideTemplate.propTypes = { }; export const pageQuery = graphql` - query($path: String!) { + query($path: String!, $relatedResourceLimit: Int!) { mdx(frontmatter: { path: { eq: $path } }) { body frontmatter {