amp-url
v1.0.2
Published
Accelerated Mobile Pages (AMP) URL API library
Downloads
3
Maintainers
Readme
node-amp-url
Accelerated Mobile Pages (AMP) URL API node.js library. It is necessary to enable API on Google Cloud Platform and obtain API key.
Install
npm install --save amp-url
Use
const AmpUrl = require('amp-url');
const ampUrl = new AmpUrl(GOOGLE_API_KEY);
ampUrl.batchGet('https://example.com/01.html').then((cdnAmpUrl) => {
// cdnAmpUrl
});
Method
batchGet(urls)
- urls
array|string
- Target URL.
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"
}
]
}
*/
});