From 62778c708bb997169ce61807b2766369dcd148cc Mon Sep 17 00:00:00 2001 From: Vince Picone Date: Mon, 10 Feb 2020 14:59:48 -0600 Subject: [PATCH] fix: enhance mediumposts component closes #692, closes #593 (#710) --- packages/example/gatsby-config.js | 1 + packages/gatsby-theme-carbon/gatsby-config.js | 23 ++++++---- packages/gatsby-theme-carbon/gatsby-node.js | 44 ++++++++++++++----- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/packages/example/gatsby-config.js b/packages/example/gatsby-config.js index 219368cad..8894dbcb8 100644 --- a/packages/example/gatsby-config.js +++ b/packages/example/gatsby-config.js @@ -21,6 +21,7 @@ module.exports = { resolve: 'gatsby-theme-carbon', options: { isSearchEnabled: true, + mediumAccount: 'carbondesign', repository: { baseUrl: 'https://github.com/carbon-design-system/gatsby-theme-carbon', diff --git a/packages/gatsby-theme-carbon/gatsby-config.js b/packages/gatsby-theme-carbon/gatsby-config.js index e8720c7e0..caa50f37b 100644 --- a/packages/gatsby-theme-carbon/gatsby-config.js +++ b/packages/gatsby-theme-carbon/gatsby-config.js @@ -18,10 +18,22 @@ module.exports = themeOptions => { lunrOptions = defaultLunrOptions, repository, pngCompressionSpeed = 4, // default for gatsby-plugin-sharp - mediumAccount = 'carbondesign', + mediumAccount = '', gatsbyRemarkPlugins = [], } = themeOptions; + const optionalPlugins = []; + + if (mediumAccount) { + optionalPlugins.push({ + resolve: 'gatsby-source-medium-feed', + options: { + userName: mediumAccount, // Medium user name + name: 'MediumFeed', // GraphQL query AllMediumFeed + }, + }); + } + const defaultRemarkPlugins = [ { resolve: `gatsby-remark-unwrap-images` }, { resolve: `gatsby-remark-smartypants` }, @@ -121,13 +133,6 @@ module.exports = themeOptions => { }, }, `gatsby-plugin-react-helmet`, - { - resolve: 'gatsby-source-medium-feed', - options: { - userName: mediumAccount, // Medium user name - name: 'MediumFeed', // GraphQL query AllMediumFeed - }, - }, - ], + ].concat(optionalPlugins), }; }; diff --git a/packages/gatsby-theme-carbon/gatsby-node.js b/packages/gatsby-theme-carbon/gatsby-node.js index 296062976..ebe057b22 100644 --- a/packages/gatsby-theme-carbon/gatsby-node.js +++ b/packages/gatsby-theme-carbon/gatsby-node.js @@ -50,17 +50,39 @@ exports.onCreatePage = ( // were providing at least 1 nested page, but that resulted in the bottom navigation to that page // reading "Resources: Resources" (as an example). By overriding the type definitions for // NavItemsYaml we can allow the title to be nullable, which fixes this issue. -exports.sourceNodes = ({ actions }) => { + +// Create medium feed schema incase the plugin isn't used or you're on an ✈️ +exports.createSchemaCustomization = ({ actions, schema }) => { const { createTypes } = actions; - const typeDefs = ` - type NavItemsYamlPage { - title: String - path: String! - } - type NavItemsYaml implements Node { - title: String! - pages: [NavItemsYamlPage]! - } - `; + + const typeDefs = [ + ` + type NavItemsYamlPage { + title: String + path: String! + } + type NavItemsYaml implements Node { + title: String! + pages: [NavItemsYamlPage]! + }`, + schema.buildObjectType({ + name: 'MediumFeed', + interfaces: ['Node'], + fields: { + author: 'String', + slug: 'String', + thumbnail: 'String', + title: 'String', + link: 'String', + date: { + type: 'Date', + extensions: { + dateformat: {}, + }, + }, + }, + }), + ]; + createTypes(typeDefs); };