grunt-appolo-assets-url-replace
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "grunt-appolo-assets-url-replace", | ||
"description": "Grunt task to replace assets urls with absolute path", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Roman Svichar", |
@@ -10,6 +10,5 @@ | ||
//var imgRegex = /url\s?\(['"]?(.*?)(?=['"]?\))/gi; | ||
var cssRegex = /url\s*\(\s*(['"]?)([^"'\)]*)\1\s*\)/gi; | ||
var htmlRegex = /src\s?\=['"]?(.*)['"]/gi; | ||
var htmlRegexSrc = /src\s?\=['"]?(.*)['"]/gi; | ||
var htmlRegexHref = /href\s?\=['"]?(.*)['"]/gi; | ||
@@ -23,3 +22,3 @@ | ||
staticUrl: 'public', | ||
ext: ['.png', '.jpeg', '.jpg', '.gif'] | ||
ext: ['.png', '.jpeg', '.jpg', '.gif', '.js', '.css'] | ||
}); | ||
@@ -63,3 +62,3 @@ | ||
while(match = htmlRegex.exec(html)) { | ||
while(match = htmlRegexSrc.exec(html)) { | ||
var imagePath = match[1]; | ||
@@ -71,3 +70,3 @@ | ||
options.ext.indexOf(path.extname(imagePath)) > -1 ) { | ||
html = html.replace(match[0], 'src="'+options.staticUrl + path.normalize('/'+ imagePath)+'"'); | ||
html = html.replace(match[0], 'src="'+ options.staticUrl + path.normalize('/'+ imagePath)+'"'); | ||
modified = true; | ||
@@ -77,2 +76,14 @@ } | ||
while(match = htmlRegexHref.exec(html)) { | ||
var imagePath = match[1]; | ||
if (imagePath.indexOf("http://") == -1 && | ||
imagePath.indexOf("https://") == -1 && | ||
imagePath.indexOf(";base64") == -1 && | ||
options.ext.indexOf(path.extname(imagePath)) > -1 ) { | ||
html = html.replace(match[0], 'href="'+ options.staticUrl + path.normalize('/'+ imagePath)+'"'); | ||
modified = true; | ||
} | ||
} | ||
if(modified) { | ||
@@ -79,0 +90,0 @@ grunt.file.write(filepath, html); |
7609
8
124