Comparing version 0.1.5 to 0.2.0
@@ -10,2 +10,5 @@ 'use strict'; | ||
, async = require('async') | ||
, url = require('url') | ||
, http = require('http') | ||
, sizeOf = require('image-size') | ||
, helpers = require('./helpers'); | ||
@@ -98,2 +101,17 @@ | ||
function enter(error) { | ||
if (error) { | ||
return done(error); | ||
} | ||
children = element.children; | ||
html += helpers[element.type](element); | ||
if (!children || !children.length) return close(null, html); | ||
setImmediate(function delay() { | ||
traverse.call(amperize, children, html, close); | ||
}); | ||
} | ||
if (element.name === 'img' && amperize.config.img) { | ||
@@ -105,12 +123,22 @@ element.name = 'amp-img'; | ||
} | ||
} | ||
children = element.children; | ||
html += helpers[element.type](element); | ||
if ((!element.attribs.width || !element.attribs.height) && element.attribs.src.indexOf('http') === 0) { | ||
var options = url.parse(element.attribs.src); | ||
if (!children || !children.length) return close(null, html); | ||
return http.get(options, function (response) { | ||
var chunks = []; | ||
setImmediate(function delay() { | ||
traverse.call(amperize, children, html, close); | ||
}); | ||
response.on('data', function (chunk) { | ||
chunks.push(chunk); | ||
}).on('end', function () { | ||
var dimensions = sizeOf(Buffer.concat(chunks)); | ||
element.attribs.width = dimensions.width; | ||
element.attribs.height = dimensions.height; | ||
return enter(); | ||
}); | ||
}); | ||
} | ||
} | ||
return enter(); | ||
}, done); | ||
@@ -117,0 +145,0 @@ }; |
{ | ||
"name": "amperize", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "AMP up your plain HTML", | ||
@@ -30,2 +30,3 @@ "main": "./lib/amperize", | ||
"htmlparser2": "3.8.3", | ||
"image-size": "0.3.5", | ||
"lodash.merge": "3.3.2", | ||
@@ -32,0 +33,0 @@ "node-uuid": "1.4.3" |
@@ -68,4 +68,4 @@ 'use strict'; | ||
it('transforms <img> into <amp-img></amp-img>', function () { | ||
amperize.parse('<img src="foo">', function (error, result) { | ||
expect(result).to.be.equal('<amp-img src="foo" layout="responsive"></amp-img>'); | ||
amperize.parse('<img src="http://lorempixel.com/output/abstract-q-c-640-480-3.jpg">', function (error, result) { | ||
expect(result).to.be.equal('<amp-img src="http://lorempixel.com/output/abstract-q-c-640-480-3.jpg" layout="responsive" width="640" height="480"></amp-img>'); | ||
}); | ||
@@ -72,0 +72,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13469
312
6
1
+ Addedimage-size@0.3.5
+ Addedimage-size@0.3.5(transitive)