Accelerated Mobile Pages (AMP) URL API library
npm install amp-urlAccelerated Mobile Pages (AMP) URL API node.js library.
It is necessary to enable API on Google Cloud Platform and obtain API key.
``shell`
npm install --save amp-url
`js
const AmpUrl = require('amp-url');
const ampUrl = new AmpUrl(GOOGLE_API_KEY);
ampUrl.batchGet('https://example.com/01.html').then((cdnAmpUrl) => {
// cdnAmpUrl
});
`
- urls array|string - Target URL.
`js
const AmpUrl = require('amp-url');
const ampUrl = new AmpUrl(GOOGLE_API_KEY);
ampUrl.batchGet([
'https://example.com/01.html',
'https://example.com/02.html',
'https://example.com/03.html'
]).then((cdnAmpUrl) => {
/* Example
{
"ampUrls": [
[
{
"originalUrl": "https://example.com/01.html",
"ampUrl": "https://example.com/amp/01.html",
"cdnAmpUrl": "https://example-com.cdn.ampproject.org/c/s/example.com/amp/01.html"
},
{
"originalUrl": "https://example.com/02.html",
"ampUrl": "https://example.com/amp/02.html",
"cdnAmpUrl": "https://example-com.cdn.ampproject.org/c/s/example.com/amp/02.htmls"
}
]
],
"urlErrors": [
{
"errorCode": "URL_IS_INVALID_AMP",
"errorMessage": "Request URL is an invalid AMP URL.",
"originalUrl": "https://example.com/03.html"
}
]
}
*/
});
``