-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Closed
Labels
good first issueIssue that doesn't require previous experience with GatsbyIssue that doesn't require previous experience with Gatsby
Description
Summary
We recently added a createContentDigest helper which is exposed to any gatsby plugin. This internalizes the unique key creation, which changes based on changing content.
We've added this to several packages, and we should now add it to any/all packages.
Basic example
Any plugin that implements the following code snippet (or close to it) can be refactored with this new helper:
const crypto = require(`crypto`)
module.exports = ({ createNode }) => {
const obj = { whatever: true }
// this is the key one!
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(obj))
.digest(`hex`)
createNode() // use content digest
}can be replaced with
const { createContentDigest } = require('gatsby-core-utils');
module.exports = ({ createNode }) => {
const obj = { whatever: true }
// this is the key one!
const contentDigest = createContentDigest(obj)
createNode() // use content digest
}Motivation
Cleaning up code and keeping it DRY 💪
Additional Info
Any plugin that implements this new API should also bump it's peerDependency on gatsby, e.g.
{
"peerDependencies": {
"gatsby": ">2.0.15"
}
}Metadata
Metadata
Assignees
Labels
good first issueIssue that doesn't require previous experience with GatsbyIssue that doesn't require previous experience with Gatsby