New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

postxml-amp

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postxml-amp - npm Package Compare versions

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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc