Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-plugin-amp

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-amp - npm Package Compare versions

Comparing version 0.1.16 to 0.1.17

108

gatsby-ssr.js

@@ -6,6 +6,10 @@ "use strict";

exports.__esModule = true;
exports.onRenderBody = exports.onPreRenderHTML = void 0;
exports.replaceRenderer = exports.onRenderBody = exports.onPreRenderHTML = void 0;
var _react = _interopRequireWildcard(require("react"));
var _server = require("react-dom/server");
var _jsdom = require("jsdom");
var _jsxFileName = "/Users/jfaircloth/GitHub/gatsby-plugin-amp/src/gatsby-ssr.js";

@@ -50,3 +54,3 @@ const ampBoilerplate = `body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}`;

fileName: _jsxFileName,
lineNumber: 39
lineNumber: 41
},

@@ -61,3 +65,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 40
lineNumber: 42
},

@@ -68,3 +72,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 44
lineNumber: 46
},

@@ -79,3 +83,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 45
lineNumber: 47
},

@@ -90,3 +94,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 50
lineNumber: 52
},

@@ -100,3 +104,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 52
lineNumber: 54
},

@@ -110,3 +114,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 59
lineNumber: 61
},

@@ -117,3 +121,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 65
lineNumber: 67
},

@@ -130,3 +134,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 77
lineNumber: 79
},

@@ -162,3 +166,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 97
lineNumber: 99
},

@@ -171,3 +175,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 102
lineNumber: 104
},

@@ -178,3 +182,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 104
lineNumber: 106
},

@@ -189,3 +193,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 109
lineNumber: 111
},

@@ -196,3 +200,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 117
lineNumber: 119
},

@@ -209,3 +213,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 119
lineNumber: 121
},

@@ -216,3 +220,3 @@ __self: void 0

fileName: _jsxFileName,
lineNumber: 130
lineNumber: 132
},

@@ -224,2 +228,70 @@ __self: void 0

exports.onRenderBody = onRenderBody;
exports.onRenderBody = onRenderBody;
const replaceRenderer = ({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents,
pathname
}, {
pathIdentifier
}) => {
const defaults = {
image: {
width: 640,
height: 475,
layout: "responsive"
}
};
const headComponents = [];
const isAmp = pathname.indexOf(pathIdentifier) > -1;
if (isAmp) {
const bodyHTML = (0, _server.renderToString)(bodyComponent);
const dom = new _jsdom.JSDOM(bodyHTML);
const document = dom.window.document;
const images = [].slice.call(document.getElementsByTagName("img"));
images.forEach(image => {
let ampImage;
if (image.src.indexOf(".gif") > -1) {
ampImage = document.createElement("amp-anim");
headComponents.push("amp-anim");
} else {
ampImage = document.createElement("amp-img");
}
const attributes = Object.keys(image.attributes);
const includedAttributes = attributes.map(key => {
const attribute = image.attributes[key];
ampImage.setAttribute(attribute.name, attribute.value);
return attribute.name;
});
Object.keys(defaults.image).forEach(key => {
if (includedAttributes.indexOf(key) === -1) {
ampImage.setAttribute(key, defaults.image[key]);
}
});
image.parentNode.replaceChild(ampImage, image);
});
setHeadComponents([...new Set(headComponents)].map(x => _react.default.createElement(_react.Fragment, {
__source: {
fileName: _jsxFileName,
lineNumber: 180
},
__self: void 0
}, _react.default.createElement("script", {
async: true,
"custom-element": x,
src: `https://cdn.ampproject.org/v0/${x}-0.1.js`,
__source: {
fileName: _jsxFileName,
lineNumber: 181
},
__self: void 0
}))));
replaceBodyHTMLString(document.documentElement.outerHTML);
}
};
exports.replaceRenderer = replaceRenderer;

3

package.json
{
"name": "gatsby-plugin-amp",
"version": "0.1.16",
"version": "0.1.17",
"description": "A gatsby plugin for scaffolding AMP pages",

@@ -15,2 +15,3 @@ "main": "index.js",

"dependencies": {
"jsdom": "^13.0.0",
"react": "^16.6.1"

@@ -17,0 +18,0 @@ },

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