dear community, I want to implement gravatar in a blog to show the authors of the posts and in case they do not have an avatar, a reference image will be shown.
create a hidden label with ID referring to email
with Jquery I access the label, pass it through a code block to get the hash and send it to the DOM.
(function ($) {
“use strict”;
let email = $(’#x1’);
const { createHash } = require(‘crypto’);
function computeHash (email = ‘’) {
// Ensure email is a string
email = (typeof email === ‘string’) ? email : ‘’;
// Trim the leading and trailing whitespaces
email = email.trim();
// Transform to all lowercase characters
email = email.toLowerCase();
// Compute the MD5 hash
const hash = createHash(‘md5’).update(email).digest(‘hex’);
return hash;
}
$(’#x2’).attr(‘src’, ‘https://www.gravatar.com/avatar/’ + );
})(jQuery);
but it’s not working for me