1.0.2 • Published 5 years ago

amp-url v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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"
        }
      ]
    }
    */
});

License

MIT License.

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago