Skip to content

Commit

Permalink
♻️ Use createContentDigest helper
Browse files Browse the repository at this point in the history
  • Loading branch information
charlyx committed Mar 31, 2019
1 parent 7b5a6b8 commit 8b10d38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Array [
"children": Array [],
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "9ce7919cb3f607a0542bac4aa46136b6",
"contentDigest": "contentDigest",
"type": "",
},
"parent": "whatever",
Expand Down Expand Up @@ -45,7 +45,7 @@ Array [
"children": Array [],
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "9ce7919cb3f607a0542bac4aa46136b6",
"contentDigest": "contentDigest",
"type": "",
},
"parent": "whatever",
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-transformer-toml/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ describe(`Process TOML nodes correctly`, () => {
const actions = { createNode, createParentChildLink }
const createNodeId = jest.fn()
createNodeId.mockReturnValue(`uuid-from-gatsby`)
const createDigestContent = jest.fn().mockReturnValue(`contentDigest`)

await onCreateNode({
node,
loadNodeContent,
actions,
createNodeId,
createDigestContent,
}).then(() => {
expect(createNode.mock.calls).toMatchSnapshot()
expect(createParentChildLink.mock.calls).toMatchSnapshot()
expect(createNode).toHaveBeenCalledTimes(1)
expect(createParentChildLink).toHaveBeenCalledTimes(1)
expect(createDigestContent).toHaveBeenCalledTimes(1)
})
})

Expand Down
14 changes: 8 additions & 6 deletions packages/gatsby-transformer-toml/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const toml = require(`toml`)
const _ = require(`lodash`)
const crypto = require(`crypto`)

async function onCreateNode({ node, actions, loadNodeContent, createNodeId }) {
async function onCreateNode({
node,
actions,
loadNodeContent,
createNodeId,
createDigestContent,
}) {
const { createNode, createParentChildLink } = actions
// Filter out non-toml content
// Currently TOML files are considered null in 'mime-db'
Expand All @@ -19,10 +24,7 @@ async function onCreateNode({ node, actions, loadNodeContent, createNodeId }) {
// 1) More TOML files -> more types
// 2) Different files with the same name creating conflicts
const parsedContentStr = JSON.stringify(parsedContent)
const contentDigest = crypto
.createHash(`md5`)
.update(parsedContentStr)
.digest(`hex`)
const contentDigest = createDigestContent(parsedContentStr)

const newNode = {
...parsedContent,
Expand Down

0 comments on commit 8b10d38

Please sign in to comment.