-
-
Save icetee/2b417c6339f19cfcc03b3c243a158fc7 to your computer and use it in GitHub Desktop.
Handlebars.js - Gravatar thumbnail #handlebars #cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handlebars.js - Gravatar thumbnail | |
// Usage: {{#gravatar email size="64"}}{{/gravatar}} | |
// Thanks: @tracend | |
import crypto from 'crypto'; | |
import Handlebars from 'handlebars/runtime'; | |
Handlebars.registerHelper('gravatar', (context, options) => { | |
const email = context; | |
const size = (typeof (options.hash.size) === 'undefined') ? 32 : options.hash.size; | |
const hash = crypto.createHash('md5').update(email).digest('hex'); | |
return `https://www.gravatar.com/avatar/${hash}?s=${size}`; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment