postxml-amp
Advanced tools
Comparing version 0.1.0 to 0.2.0
31
index.js
var fs = require('fs'); | ||
var sizeOf = require('image-size'); | ||
var request = require('sync-request'); | ||
var cleanCss = require('clean-css'); | ||
module.exports = function (options) { | ||
module.exports = function(options) { | ||
var tags = { | ||
@@ -12,17 +13,16 @@ amp: ['img', 'video'] | ||
var options = options || {}; | ||
options.cwd = options.cwd || ''; | ||
options.round = options.round || true; | ||
if (options.round) { | ||
round = function (numb) { | ||
return Math.round(numb / 5) * 5 | ||
} | ||
} else { | ||
round = function (numb) { | ||
return numb; | ||
} | ||
round = function(numb) { return Math.round(numb / 5) * 5; } | ||
} | ||
else { | ||
round = function(numb) { return numb; } | ||
} | ||
return function ($) { | ||
return function($) { | ||
/* html ⚡ */ | ||
$('html').each(function () { | ||
$('html').each(function() { | ||
$(this).attr('amp', ''); | ||
@@ -32,3 +32,3 @@ }); | ||
/* amp-img, amp-video */ | ||
$(tags.amp.join(',')).each(function () { | ||
$(tags.amp.join(',')).each(function() { | ||
this.name = 'amp-' + this.name; | ||
@@ -38,3 +38,3 @@ }); | ||
/* local amp-img */ | ||
$('amp-img[src]:not([src*="//"]):not(width):not(height)').each(function () { | ||
$('amp-img[src]:not([src*="//"]):not(width):not(height)').each(function() { | ||
var image = options.cwd + '/' + $(this).attr('src'); | ||
@@ -51,3 +51,3 @@ if (fs.existsSync(image)) { | ||
/* remote amp-img */ | ||
$('amp-img[src*="//"]:not(width):not(height)').each(function () { | ||
$('amp-img[src*="//"]:not(width):not(height)').each(function() { | ||
var imageUrl = this.attribs.src; | ||
@@ -65,3 +65,3 @@ var response = request('GET', imageUrl); | ||
/* inline styles */ | ||
$('link[rel=stylesheet]').each(function () { | ||
$('link[rel=stylesheet]').each(function() { | ||
var src = $(this).attr('href'); | ||
@@ -71,3 +71,4 @@ var path = src; | ||
var setFile = function (data) { | ||
return '<style amp-custom>' + data + '</style>'; | ||
var minified = new cleanCss().minify(data).styles; | ||
return '<style amp-custom>' + minified + '</style>'; | ||
}; | ||
@@ -74,0 +75,0 @@ |
{ | ||
"name": "postxml-amp", | ||
"version": "0.1.0", | ||
"description": "Postxml plugin to convert plain HTML to Google Accelerated Mobile Pages (AMP)", | ||
"version": "0.2.0", | ||
"description": "PostXML plugin to convert plain HTML to Google Accelerated Mobile Pages (AMP)", | ||
"main": "index.js", | ||
"dependencies": { | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"clean-css": "^3.4.10", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^1.1.1", | ||
"gulp-mocha": "^2.2.0", | ||
"image-size": "^0.4.0", | ||
"postxml": "^0.2.9", | ||
"sync-request": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"gulp": "^3.9.0", | ||
"gulp-eslint": "^1.0.0", | ||
"gulp-mocha": "^2.1.3", | ||
"postxml": "^0.2.4" | ||
}, | ||
"scripts": { | ||
@@ -25,3 +24,11 @@ "test": "mocha", | ||
}, | ||
"keywords": [], | ||
"keywords": [ | ||
"html", | ||
"plugin", | ||
"postxml", | ||
"transform", | ||
"amp", | ||
"amp-img", | ||
"amp-video" | ||
], | ||
"author": { | ||
@@ -28,0 +35,0 @@ "name": "rkazakov", |
@@ -1,24 +0,45 @@ | ||
# PostXML plugin boilerplate | ||
# postxml-amp | ||
[![npm version][npm-image]][npm-url] | ||
> [PostXML] plugin boilerplate. | ||
> [PostXML] plugin to convert plain HTML to Google Accelerated Mobile Pages (AMP). | ||
## Installation | ||
`npm install postxml-amp --save-dev` | ||
## Usage | ||
1. Clone this repository | ||
``` | ||
git clone https://github.com/postxml/postxml-plugin-boilerplate.git | ||
``` | ||
2. Fill `plugin.json` | ||
3. Run | ||
``` | ||
node plugin.js | ||
``` | ||
4. Install packages | ||
``` | ||
npm i | ||
``` | ||
5. Develop | ||
``` | ||
gulp | ||
``` | ||
[Postxml] | ||
## Options | ||
### cwd | ||
**Assets (images/styles) file path**<br> | ||
Type: `String`<br> | ||
Default: `''` | ||
### round | ||
**Enable images dimensions rounding**<br> | ||
Type: `String`<br> | ||
Default: `true` | ||
## Example | ||
### Input | ||
```html | ||
<html><head><link rel="stylesheet" href="style.css"></head><img src="image.png"></html> | ||
``` | ||
###### image.png | ||
[image.png](/test/image.png) | ||
###### style.css | ||
```css | ||
body { | ||
background-color: #FFF; | ||
} | ||
``` | ||
### Output | ||
```html | ||
<html amp=""><head><style amp-custom="">body{background-color:#FFF}</style></head><amp-img src="image.png" width="600" height="400"></amp-img></html> | ||
``` | ||
## Licence | ||
@@ -28,1 +49,3 @@ MIT | ||
[PostXML]: https://github.com/postxml/postxml | ||
[npm-url]: https://www.npmjs.org/package/postxml-amp | ||
[npm-image]: http://img.shields.io/npm/v/postxml-amp.svg?style=flat-square |
0
51
1
5997
8
6
90
- Removedimage-size@^0.4.0
- Removedsync-request@^3.0.0
- Removedasap@2.0.6(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-basic@2.5.1(transitive)
- Removedhttp-response-object@1.1.0(transitive)
- Removedimage-size@0.4.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedobject-inspect@1.13.4(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpromise@7.3.1(transitive)
- Removedqs@6.14.0(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedsync-request@3.0.1(transitive)
- Removedthen-request@2.2.0(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)