Skip to content

Instantly share code, notes, and snippets.

@mpr0xy
Last active August 29, 2015 14:25
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 mpr0xy/6e4c41424f389e116139 to your computer and use it in GitHub Desktop.
Save mpr0xy/6e4c41424f389e116139 to your computer and use it in GitHub Desktop.
mp-gulp-img-src
var through = require('through2');
module.exports = function() {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-mp-upai-upload', 'Streaming not supported'));
return;
}
var fileContext = file.contents.toString();
var imgReg_g = /<img.+src=('|")(\S+)('|")\s/gi;
var imgReg = /<img.+src=('|")(\S+)('|")\s/i;
var foundImg_array = fileContext.match(imgReg_g);
foundImg_array.forEach(function(item, index) {
var results = foundImg_array[index].match(imgReg);
if (results) {
console.log(results[2]);
}
})
// console.log(foundImg_array);
cb();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment