Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Aug 9, 2017
1 parent e304813 commit 34e1ca6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-xml/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gatsby-transformer-xml

Parses JXML files. It supports also attributes
Parses XML files. It supports also attributes

## Install

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Promise = require(`bluebird`)

const { onCreateNode } = require(`../gatsby-node`)
describe(`Process XML nodes correctly`, () => {
const node = {
Expand Down
26 changes: 11 additions & 15 deletions packages/gatsby-transformer-xml/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _ = require(`lodash`)

async function onCreateNode({ node, boundActionCreators, loadNodeContent }) {
const { createNode, createParentChildLink } = boundActionCreators

// We only care about XML content.
if (![`application/xml`, `text/xml`].includes(node.internal.mediaType)) {
return
Expand All @@ -13,27 +13,23 @@ async function onCreateNode({ node, boundActionCreators, loadNodeContent }) {
const parsedXml = parseXml(rawXml)
const nodeArray = parsedXml.root.children.map((obj, i) => {
const objStr = JSON.stringify(obj)
const contentDigest = crypto
.createHash(`md5`)
.update(objStr)
.digest(`hex`)
const contentDigest = crypto.createHash(`md5`).update(objStr).digest(`hex`)
return {
...obj,
id: obj.attributes.id ? obj.attributes.id : `${node.id} [${i}] >>> XML`,
parent: node.id,
internal: {
contentDigest,
type: _.upperFirst(_.camelCase(`${node.name} xml`)),
},
}
...obj,
id: obj.attributes.id ? obj.attributes.id : `${node.id} [${i}] >>> XML`,
parent: node.id,
internal: {
contentDigest,
type: _.upperFirst(_.camelCase(`${node.name} xml`)),
},
}
})

_.each(nodeArray, j => {
createNode(j)
createParentChildLink({ parent: node, child: j })
createParentChildLink({ parent: node, child: j })
})
return
}

exports.onCreateNode = onCreateNode

0 comments on commit 34e1ca6

Please sign in to comment.