gatsby-plugin-amp
Advanced tools
Comparing version 0.1.16 to 0.1.17
@@ -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; |
{ | ||
"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 @@ }, |
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
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
15455
262
2
+ Addedjsdom@^13.0.0
+ Addedabab@2.0.6(transitive)
+ Addedacorn@6.4.2(transitive)
+ Addedacorn-globals@4.3.4(transitive)
+ Addedacorn-walk@6.2.0(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedarray-equal@1.0.2(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasync-limiter@1.0.1(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbrowser-process-hrtime@1.0.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcssom@0.3.8(transitive)
+ Addedcssstyle@1.4.0(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddata-urls@1.1.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddomexception@1.0.1(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhtml-encoding-sniffer@1.0.2(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjsdom@13.2.0(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.sortby@4.7.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednwsapi@2.2.13(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedparse5@5.1.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpn@1.1.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedrequest-promise-native@1.0.9(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsaxes@3.1.11(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstealthy-require@1.1.1(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtr46@1.0.1(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedw3c-hr-time@1.0.2(transitive)
+ Addedw3c-xmlserializer@1.1.2(transitive)
+ Addedwebidl-conversions@4.0.2(transitive)
+ Addedwhatwg-encoding@1.0.5(transitive)
+ Addedwhatwg-mimetype@2.3.0(transitive)
+ Addedwhatwg-url@7.1.0(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedws@6.2.3(transitive)
+ Addedxml-name-validator@3.0.0(transitive)
+ Addedxmlchars@2.2.0(transitive)