Convert plain HTML to Google Accelerated Mobile Pages (AMP)
npm install ampify[![NPM Version][npm-image]][npm-url]
[![Downloads Stats][npm-downloads]][npm-url]




> Convert plain HTML to Google AMP (Accelerated Mobile Pages)
``sh`
npm install ampify
`js`
const ampify = require('ampify');
const html = '
const amp = ampify(html, {
cwd: 'amp',
canonicalURL: 'https://
});
console.log(amp); // Content of AMP HTML
#### Assets (images/styles) file path
- Type: String''
- Default:
#### Enable images dimensions rounding
- Type: Stringtrue
- Default:
- Default: ''Cannonical URL should be a full valid URL. Please see Make your pages discoverable.
Example
$3
`html

`#### image.png
#### style.css
`css
body {
background-color: #fff;
}
`$3
`html
`More examples
See
/examples folder for full source code.$3
`js
const ampify = require('ampify');
const express = require('express');const app = express();
app.get('/article', async (req, res) => {
const html =
This is an AMP article
; const amp = await ampify(html, {cwd: 'amp'});
res.send(amp); // serving AMP content
});
app.listen(3000, () => {
console.log('Listening on port 3000!');
});
`$3
`js
const ampify = require('ampify');
const express = require('express');const app = express();
app.use((req, res, next) => {
if (req.url.startsWith('/amp')) {
const send = res.send;
res.send = async (html) => {
const amp = await ampify(html, {cwd: 'amp'});
send.call(this, amp);
};
}
next();
});
app.get('/amp/article', (req, res) => {
const html =
This is AMP article
;
res.send(html);
});app.get('/article', (req, res) => {
const html =
This is HTML article
;
res.send(html);
});app.listen(3000, () => {
console.log('Listening on port 3000!');
});
``MIT (c) Ruslan Kazakov and 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