Created
July 9, 2013 01:21
-
-
Save lepture/5953897 to your computer and use it in GitHub Desktop.
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
var md5 = require('md5'); | |
const SUBSTITUTE_BASE = 'https://example.com/'; | |
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