From 9b3a1680fbf6ad066e80dc144f1f4a99a4eadab2 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Wed, 11 Sep 2019 01:45:31 +0430 Subject: [PATCH] fix(amp-validator): fix amp detection in render hook --- lib/amp/plugin.js | 8 +++++++- lib/module.js | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/amp/plugin.js b/lib/amp/plugin.js index 847d96dd..20401198 100644 --- a/lib/amp/plugin.js +++ b/lib/amp/plugin.js @@ -38,7 +38,13 @@ export default function ({ route, req }, inject) { break } - inject('req', req || {}) + const $request = req || {} + /** + * This will use to detect amp request on render hook + */ + $request.isAMP = isAMP + + inject('req', $request) inject('isAMP', isAMP) inject('ampMode', ampMode) } diff --git a/lib/module.js b/lib/module.js index 7119f8f6..f720a4c7 100644 --- a/lib/module.js +++ b/lib/module.js @@ -47,8 +47,8 @@ function processRoutes (routes) { async function registerValidator (options) { const amphtmlValidator = require('amphtml-validator') const validator = await amphtmlValidator.getInstance() - this.nuxt.hook('render:route', (url, { html }) => { - const isAMP = html.includes('data-n-head="amp"') + this.nuxt.hook('render:route', (url, { html }, { req }) => { + const isAMP = req.isAMP if (isAMP) { const result = validator.validateString(html)