Skip to content

Commit

Permalink
fix: enhance mediumposts component closes #692, closes #593 (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone authored Feb 10, 2020
1 parent b431b4d commit 62778c7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/example/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 14 additions & 9 deletions packages/gatsby-theme-carbon/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` },
Expand Down Expand Up @@ -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),
};
};
44 changes: 33 additions & 11 deletions packages/gatsby-theme-carbon/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 62778c7

Please sign in to comment.