Skip to content

Commit

Permalink
Merge pull request #4 from osk2/master
Browse files Browse the repository at this point in the history
Some improvements
  • Loading branch information
rkazakov authored Apr 4, 2017
2 parents e5dc5ac + 1c7de6d commit 9ebb62b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,35 @@ npm install ampify --save-dev

## Usage

```js
const ampify = require('ampify');
const html = 'YOUR_HTML_CONTENT';
const amp = ampify(html, {cwd: 'amp'});

console.log(amp) // Content of AMP HTML
```

## Options
### cwd
**Assets (images/styles) file path**<br>
Type: `String`<br>
**Assets (images/styles) file path**
Type: `String`
Default: `''`

### round
**Enable images dimensions rounding**<br>
Type: `String`<br>
**Enable images dimensions rounding**
Type: `String`
Default: `true`

## Example

### Input
```html
<html><head><link rel="stylesheet" href="style.css"></head><img src="image.png"></html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<img src="image.png">
</html>
```

###### image.png
Expand All @@ -48,7 +60,7 @@ body {
## Release History

* 0.2.4
* UPDATE: package.json
* UPDATE: package.json
* 0.2.3
* ADD: meta tag viewport
* ADD: style amp-boilerplate
Expand Down
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ module.exports = function(html, options) {

/* head */

/* main amp library */
$('head script[src="https://cdn.ampproject.org/v0.js"]').remove();
$('head').prepend('<script async src="https://cdn.ampproject.org/v0.js"></script>');

/* meta charset */
if ($('head meta[charset="utf-8"]').length === 0) {
$('head').append('<meta charset="utf-8">');
}
$('head meta[charset="utf-8"]').remove();
$('head meta[charset="UTF-8"]').remove();
$('head').prepend('<meta charset="utf-8">');

/* meta viewport */
if ($('head meta[content="width=device-width,minimum-scale=1,initial-scale=1"]').length === 0) {
Expand All @@ -50,14 +54,12 @@ module.exports = function(html, options) {
$('head').append('<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>');
}

/* main amp library */
if ($('head script[src="https://cdn.ampproject.org/v0.js"]').length === 0) {
$('head').append('<script async src="https://cdn.ampproject.org/v0.js"></script>');
}

/* img dimensions */
$('img:not(width):not(height)').each(function() {
var src = $(this).attr('src');
if (!src) {
return $(this).remove();
}
if (src.indexOf('//') === -1) {
var image = options.cwd + '/' + $(this).attr('src');
if (fs.existsSync(image)) {
Expand Down
Loading

0 comments on commit 9ebb62b

Please sign in to comment.