@bradymholt/ampify
Advanced tools
Comparing version 0.3.0 to 1.0.0
13
index.js
@@ -60,3 +60,6 @@ const fs = require("fs"); | ||
const el = $(element); | ||
if (el.attr("src") && el.attr("src").indexOf("cdn.ampproject.org") > -1) { | ||
if ( | ||
(el.attr("src") && el.attr("src").indexOf("cdn.ampproject.org") > -1) || | ||
el.parent()[0].tagName.startsWith("amp-") | ||
) { | ||
// This is an AMP script so leave it alone | ||
@@ -191,5 +194,7 @@ return; | ||
// Add styles to <head/> | ||
const scrubbedStyles = scrubCss(styles); | ||
headElement.find("style[amp-custom]").remove(); | ||
headElement.append(`<style amp-custom>${scrubbedStyles}</style>`); | ||
if (styles) { | ||
const scrubbedStyles = scrubCss(styles); | ||
headElement.find("style[amp-custom]").remove(); | ||
headElement.append(`<style amp-custom>${scrubbedStyles}</style>`); | ||
} | ||
@@ -196,0 +201,0 @@ // Handle iframes |
{ | ||
"name": "@bradymholt/ampify", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
@@ -14,5 +14,5 @@ # ampify | ||
```js | ||
const ampify = require('ampify'); | ||
const html = '<YOUR_HTML_CONTENT>'; | ||
const amp = await ampify(html, {cwd: 'amp'}); | ||
const ampify = require("ampify"); | ||
const html = "<YOUR_HTML_CONTENT>"; | ||
const amp = await ampify(html, { cwd: "amp" }); | ||
console.log(amp); // Content of AMP HTML | ||
@@ -27,2 +27,4 @@ ``` | ||
When `<link rel=stylesheet>` and `<img/>` tags with a local file reference are encountered, they will read and processed. This option specifies where the files are located (i.e. `` fs.existsSync(`${options.cwd}/${imagSrc}`)) ``. | ||
- Type: `String` | ||
@@ -45,5 +47,7 @@ - Default: `''` | ||
<head> | ||
<link rel="stylesheet" href="styles.css"> | ||
<link rel="stylesheet" href="styles.css" /> | ||
</head> | ||
<img src="image.png"> | ||
<body> | ||
<img src="image.png" /> | ||
</body> | ||
</html> | ||
@@ -55,17 +59,16 @@ ``` | ||
```html | ||
<html amp=""> | ||
<html amp> | ||
<head> | ||
<style amp-custom="">body{background-color:#fff}</style> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
<style amp-boilerplate>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}}</style> | ||
<noscript> | ||
<style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style> | ||
</noscript> | ||
<script async src="https://cdn.ampproject.org/v0.js"></script> | ||
</head> | ||
<amp-img src="image.png" width="600" height="400"></amp-img> | ||
<body> | ||
<amp-img src="image.png" width="600" height="400"></amp-img> | ||
</body> | ||
</html> | ||
``` | ||
## Licence | ||
MIT (c) Ruslan Kazakov and [contributors](https://github.com/rkazakov/ampify/graphs/contributors) | ||
[PostXML]: https://github.com/postxml/postxml | ||
[npm-url]: https://www.npmjs.org/package/ampify | ||
[npm-image]: https://img.shields.io/npm/v/ampify.svg?style=flat-square | ||
[npm-downloads]: https://img.shields.io/npm/dm/ampify.svg?style=flat-square |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
13897
257
0
71