Skip to content

Commit

Permalink
Use browser-compatible md5 & support Gatsby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleabmelkie committed Apr 28, 2021
1 parent 1d1252b commit 1f72156
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 347 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn format && git update-index --again
2 changes: 1 addition & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ exports.sourceNodes = async ({ actions }, configOptions = {}) => {
const { createNode } = actions
const { emails = [], query = '' } = configOptions

emails.forEach(email => createNode(parseNode(email, query)))
emails.forEach((email) => createNode(parseNode(email, query)))
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
"test": "echo \"No tests yet.\" && exit 0"
},
"peerDependencies": {
"gatsby": "^2.0.0"
"gatsby": "^2.0.0 || ^3.0.0"
},
"dependencies": {
"md5": "^2.3.0"
},
"dependencies": {},
"devDependencies": {
"husky": "^4.2.3",
"prettier": "^1.19.1"
"husky": "^6.0.0",
"prettier": "^2.2.1"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ module.exports = {
digest,
parseData,
parseNode,
toUrl
toUrl,
}
10 changes: 0 additions & 10 deletions src/lib/digest.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/lib/parse-data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const digest = require('./digest')
const md5 = require('md5')

function parseData(_email, _query = null) {
if (
Expand All @@ -10,7 +10,7 @@ function parseData(_email, _query = null) {
throw Error(`'email' is required in 'gatsby-source-gravatar'.`)

const email = typeof _email === 'string' ? _email : _email.email
const hash = digest(email)
const hash = md5(email)
const query = typeof _email === 'object' ? _email.query : _query || null

return {
Expand All @@ -20,7 +20,7 @@ function parseData(_email, _query = null) {

email,
hash,
query
query,
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/lib/parse-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const digest = require('./digest')
const md5 = require('md5')
const parseData = require('./parse-data')

const parseNode = (email, query = null) => {
Expand All @@ -8,16 +8,16 @@ const parseNode = (email, query = null) => {
...data,

// Required fields.
id: `gravatar-${data.hash}-${digest(data.query || '')}`,
id: `gravatar-${data.hash}-${md5(data.query || '')}`,
parent: null,
children: [],
internal: {
type: `gravatar`,
contentDigest: digest(JSON.stringify(data)),
contentDigest: md5(JSON.stringify(data)),
description: `Gravatar URL for email "${data.email}" with ${
data.query ? 'query "' + data.query + '"' : 'no queries'
}.` // Optional.
}
}.`, // Optional.
},
}
}

Expand Down
Loading

0 comments on commit 1f72156

Please sign in to comment.