Skip to content

Commit

Permalink
fix(amp-validator): fix amp detection in render hook
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Sep 10, 2019
1 parent 3705201 commit 9b3a168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/amp/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9b3a168

Please sign in to comment.