diff --git a/docs/api/options.md b/docs/api/options.md index c46bc261..03168117 100644 --- a/docs/api/options.md +++ b/docs/api/options.md @@ -9,6 +9,7 @@ General options of amp module | tags | `{}` | Object of tag options | Define new tags or modify current tags, for instance if you want to use `amp-mustache` version 0.1, tags value must be `{ 'amp-mustache': { version: '0.1' } }` | | origin | `` | Any String | Main domain of website. Using this AMP modules tries to add missing canonical link for pages. | | mode | `hybrid` | `only\|hybrid\|false` | Default behaviour of amp module. (`only` all pages serve in AMP mode by default, `hybrid` pages serves in both normal and AMP mode, `false` pages does not serve AMP by default ) | +| routeAliases | `auto` | `auto\|Array` | Allows to limit route aliases to only AMP pages. With `auto` the module will create aliases for every route. If your app uses AMP only on a few routes you can provide those routes into an Array. Routes are absolute, without '/amp' prefix, eg. `['/story', '/page2']` | ## Page Options diff --git a/lib/module.js b/lib/module.js index a4acaec9..090231ab 100644 --- a/lib/module.js +++ b/lib/module.js @@ -18,6 +18,7 @@ module.exports = function (moduleOptions) { origin: '', mode: 'hybrid', tags: {}, + routeAliases: 'auto', ...this.options.amp, ...moduleOptions } @@ -31,10 +32,10 @@ module.exports = function (moduleOptions) { registerValidator.call(this, options) } - processRoutes.call(this) + processRoutes.call(this, options) } -function processRoutes () { +function processRoutes (options) { this.extendRoutes((routes) => { for (const route of routes) { route.meta = route.meta || {} @@ -45,7 +46,7 @@ function processRoutes () { if (route.path === '/amp' || route.path.indexOf('/amp/') === 0) { route.meta.amp = true - } else { + } else if (!Array.isArray(options.routeAliases) || options.routeAliases.includes(route.path)) { route.alias.push('/amp' + route.path) } }