Skip to content

Commit

Permalink
[gatsby-source-medium] fix next version (gatsbyjs#6205)
Browse files Browse the repository at this point in the history
* fix gatsby-source-medium (___NODE was linking to old style ids, wasn't adjusted after change to createNodeId)

* update using-medium example to use next version of medium plugin
  • Loading branch information
pieh authored and m-allanson committed Jun 28, 2018
1 parent 74909d0 commit fd6cc1a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/using-medium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"dependencies": {
"gatsby": "next",
"gatsby-source-medium": "^1.0.1",
"gatsby-source-medium": "next",
"react": "^16.4.0",
"react-dom": "^16.4.0"
},
Expand Down
28 changes: 21 additions & 7 deletions packages/gatsby-source-medium/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,18 @@ exports.sourceNodes = async ({ actions, createNodeId }, { username }) => {
importableResources = importableResources.concat(collections)
}

const resources = Array.prototype.concat(...importableResources)
const resources = Array.prototype
.concat(...importableResources)
.map(resource => {
return {
...resource,
medium_id: resource.id,
id: createNodeId(resource.id ? resource.id : resource.userId),
}
})

const getID = node => (node ? node.id : null)

resources.map(resource => {
convertTimestamps(resource)

Expand All @@ -71,21 +82,24 @@ exports.sourceNodes = async ({ actions, createNodeId }, { username }) => {
const links =
resource.type === `Post`
? {
author___NODE: resource.creatorId,
author___NODE: getID(
resources.find(r => r.userId === resource.creatorId)
),
}
: resource.type === `User`
? {
posts___NODE: posts
.filter(post => post.creatorId === resource.userId)
.map(post => post.id),
posts___NODE: resources
.filter(
r => r.type === `Post` && r.creatorId === resource.userId
)
.map(r => r.id),
}
: {}

const node = Object.assign(
resource,
{
id: createNodeId(resource.id ? resource.id : resource.userId),
parent: `__SOURCE__`,
parent: null,
children: [],
internal: {
type: `Medium${resource.type}`,
Expand Down

0 comments on commit fd6cc1a

Please sign in to comment.