Skip to content

Commit 8d5defd

Browse files
committed
v1.1.1
1 parent 9ecf745 commit 8d5defd

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gatsby-source-esa",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Gatsby source plugin for building websites using esa.io as a data source.",
55
"main": "gatsby-node.js",
66
"scripts": {

src/gatsby-node.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Frisbee from 'frisbee'
22
import crypto from 'crypto'
33

4+
const createContentDigest = obj =>
5+
crypto
6+
.createHash(`md5`)
7+
.update(JSON.stringify(obj))
8+
.digest(`hex`)
9+
410
exports.sourceNodes = async ({
511
boundActionCreators,
612
createNodeId
@@ -18,6 +24,8 @@ exports.sourceNodes = async ({
1824
throw 'You need to set an teamName.'
1925
}
2026

27+
const { createNode } = boundActionCreators
28+
2129
const api = new Frisbee({
2230
baseURI: 'https://api.esa.io'
2331
})
@@ -34,22 +42,35 @@ exports.sourceNodes = async ({
3442
})
3543

3644
body.posts.forEach(post => {
37-
const contentDigest = crypto
38-
.createHash(`md5`)
39-
.update(JSON.stringify(post))
40-
.digest('hex')
45+
const contentDigest = createContentDigest(post)
46+
47+
const nodeId = createNodeId(`EsaPost${post.number}`)
48+
49+
const bodyNode = {
50+
id: createNodeId(`EsaPost${post.number}Body`),
51+
parent: nodeId,
52+
children: [],
53+
internal: {
54+
type: 'EsaPostBody',
55+
mediaType: 'text/markdown',
56+
content: post.body_md,
57+
contentDigest: createContentDigest(post.body_md),
58+
},
59+
}
4160

42-
boundActionCreators.createNode({
61+
createNode({
4362
...post,
63+
body___NODE: bodyNode.id,
4464
relative_category: post.category.replace(new RegExp(`${baseCategory}/?`), ''),
45-
id: createNodeId(`EsaPost${post.number}`),
65+
id: nodeId,
4666
children: [],
47-
parent: `__SOURCE__`,
67+
parent: null,
4868
internal: {
4969
type: 'EsaPost',
5070
contentDigest,
5171
}
5272
})
73+
createNode(bodyNode)
5374
})
5475

5576
next_page = body.next_page

0 commit comments

Comments
 (0)