Skip to content

Instantly share code, notes, and snippets.

@icetee
Forked from tracend/handlebars.gravatar.js
Last active August 20, 2017 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icetee/2b417c6339f19cfcc03b3c243a158fc7 to your computer and use it in GitHub Desktop.
Save icetee/2b417c6339f19cfcc03b3c243a158fc7 to your computer and use it in GitHub Desktop.
Handlebars.js - Gravatar thumbnail #handlebars #cc
// 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