Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions docs/docs/pixabay-source-plugin-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ exports.sourceNodes = (
) => {
const { createNode } = actions

// highlight-start
// Gatsby adds a configOption that's not needed for this plugin, delete it
delete configOptions.plugins

// highlight-start
// Convert the options object into a query string
const apiOptions = queryString.stringify(configOptions)

Expand All @@ -242,10 +242,10 @@ exports.sourceNodes = (
// For each query result (or 'hit')
data.hits.forEach(photo => {
console.log("Photo data is:", photo)
// highlight-end
})
})
)
// highlight-end
}
```

Expand Down Expand Up @@ -273,7 +273,7 @@ You're ready to add the final step of your plugin - converting this data into a

### Use `createNode` function

You're adding a helper function on lines 11 to 27 and processing the data into a node on lines 44 to 47:
You're adding a helper function on lines 13 to 28 and processing the data into a node on lines 46 to 49:

```js:title=gatsby-node.js
const fetch = require("node-fetch")
Expand All @@ -286,9 +286,9 @@ exports.sourceNodes = (
const { createNode } = actions

// Gatsby adds a configOption that's not needed for this plugin, delete it
// highlight-start
delete configOptions.plugins

delete configOptions.plugins
// highlight-start
// Helper function that processes a photo to match Gatsby's node structure
const processPhoto = photo => {
const nodeId = createNodeId(`pixabay-photo-${photo.id}`)
Expand All @@ -304,10 +304,10 @@ exports.sourceNodes = (
contentDigest: createContentDigest(photo),
},
})
// highlight-end

return nodeData
}
// highlight-end

// Convert the options object into a query string
const apiOptions = queryString.stringify(configOptions)
Expand All @@ -325,10 +325,12 @@ exports.sourceNodes = (
.then(data => {
// For each query result (or 'hit')
data.hits.forEach(photo => {
// highlight-start
// Process the photo data to match the structure of a Gatsby node
const nodeData = processPhoto(photo)
// Use Gatsby's createNode helper to create a node from the node data
createNode(nodeData)
// highlight-end
})
})
)
Expand Down