Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
var md5 = require('md5');
const SUBSTITUTE_SECRET = 'a secret';
html = html.replace(/<img[^>]*src=('|")(.*?)\1[^>]*>/g, function(img) {
var src = RegExp.$2;
var digest = md5.hmac(SUBSTITUTE_SECRET, src);
var newSrc = SUBSTITUTE_BASE + digest + '/' + encodeURIComponent(src);
return img.replace(src, newSrc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment