Skip to content

Commit

Permalink
Add src
Browse files Browse the repository at this point in the history
  • Loading branch information
mottox2 committed Jan 8, 2019
1 parent 16d0b7b commit 18f2e88
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import crypto from 'crypto'
import Parser from 'rss-parser'

const createContentDigest = obj =>
crypto
.createHash(`md5`)
.update(JSON.stringify(obj))
.digest(`hex`)

exports.sourceNodes = async ({
actions,
createNodeId
}, {
url,
name,
}) => {
const { createNode } = actions
const parser = new Parser()

const feed = await parser.parseURL(url)
feed.items.forEach(item => {
const nodeId = createNodeId(item.link)
createNode({
...item,
id: nodeId,
parent: null,
children: [],
internal: {
contentDigest: createContentDigest(item),
type: `Feed${name}`
}
})
})
}

0 comments on commit 18f2e88

Please sign in to comment.