From 709f1e28a2d94d20b8f4f809a763145ab86aaf0d Mon Sep 17 00:00:00 2001 From: osk2 Date: Thu, 30 Mar 2017 16:58:34 +0800 Subject: [PATCH 1/4] Update README --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fba45d1..4389ae8 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,35 @@ npm install ampify --save-dev ## Usage +```js +const ampify = require('ampify'); +const html = 'YOUR_HTML_CONTENT'; +const amp = ampify(html, {cwd: 'amp'}); + +console.log(amp) // Content of AMP HTML +``` ## Options ### cwd -**Assets (images/styles) file path**
-Type: `String`
+**Assets (images/styles) file path** +Type: `String` Default: `''` ### round -**Enable images dimensions rounding**
-Type: `String`
+**Enable images dimensions rounding** +Type: `String` Default: `true` ## Example ### Input ```html - + + + + + + ``` ###### image.png @@ -48,7 +60,7 @@ body { ## Release History * 0.2.4 - * UPDATE: package.json + * UPDATE: package.json * 0.2.3 * ADD: meta tag viewport * ADD: style amp-boilerplate From 376044f40fd3086738958981cf99429194603d6e Mon Sep 17 00:00:00 2001 From: osk2 Date: Thu, 30 Mar 2017 17:00:37 +0800 Subject: [PATCH 2/4] Minor improvements - Move charset to first position - Move JS lib to second position - Remove invalid image element --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 989036f..50b0631 100644 --- a/index.js +++ b/index.js @@ -35,10 +35,14 @@ module.exports = function(html, options) { /* head */ + /* main amp library */ + $('head script[src="https://cdn.ampproject.org/v0.js"]').remove(); + $('head').prepend(''); + /* meta charset */ - if ($('head meta[charset="utf-8"]').length === 0) { - $('head').append(''); - } + $('head meta[charset="utf-8"]').remove(); + $('head meta[charset="UTF-8"]').remove(); + $('head').prepend(''); /* meta viewport */ if ($('head meta[content="width=device-width,minimum-scale=1,initial-scale=1"]').length === 0) { @@ -58,6 +62,9 @@ module.exports = function(html, options) { /* img dimensions */ $('img:not(width):not(height)').each(function() { var src = $(this).attr('src'); + if (!src) { + return $(this).remove(); + } if (src.indexOf('//') === -1) { var image = options.cwd + '/' + $(this).attr('src'); if (fs.existsSync(image)) { From faad0af8f3c67a1f42f7ff62779c1a728e364873 Mon Sep 17 00:00:00 2001 From: osk2 Date: Thu, 30 Mar 2017 17:07:59 +0800 Subject: [PATCH 3/4] Update test --- test/test.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/test/test.js b/test/test.js index 4f434a7..83302e5 100644 --- a/test/test.js +++ b/test/test.js @@ -28,15 +28,15 @@ describe('ampify', function() { it('should include meta tag with utf-8 charset attribute', function () { test( '', - '', + '', {} ); }); it('should not include meta tag if it is already there', function () { test( - '', - '', + '', + '', {} ); }); @@ -48,15 +48,15 @@ describe('ampify', function() { it('should include meta viewport tag with content attribute', function () { test( '', - '', + '', {} ); }); it('should not include meta viewport tag if it is already there', function () { test( - '', - '', + '', + '', {} ); }); @@ -68,15 +68,15 @@ describe('ampify', function() { it('should include style amp-boilerplate tag', function () { test( '', - '', + '', {} ); }); it('should not include style amp-boilerplate tag if it is already there', function () { test( - '', - '', + '', + '', {} ); }); @@ -88,7 +88,7 @@ describe('ampify', function() { it('should include amp library script tag', function () { test( '', - '', + '', {} ); }); @@ -136,6 +136,15 @@ describe('ampify', function() { ); }); + it('should remove invalid img tag', function() { + test( + '', + '', + {} + ); + }); + + }); describe('amp-video tag', function() { From 1c7de6df912176bb5c87c62722fb296def6f06d4 Mon Sep 17 00:00:00 2001 From: osk2 Date: Thu, 30 Mar 2017 17:31:14 +0800 Subject: [PATCH 4/4] Clean-up code --- index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/index.js b/index.js index 50b0631..3e4bfa5 100644 --- a/index.js +++ b/index.js @@ -54,11 +54,6 @@ module.exports = function(html, options) { $('head').append(''); } - /* main amp library */ - if ($('head script[src="https://cdn.ampproject.org/v0.js"]').length === 0) { - $('head').append(''); - } - /* img dimensions */ $('img:not(width):not(height)').each(function() { var src = $(this).attr('src');