vue-meta
vue-meta copied to clipboard
Remove 'data-n-head' and 'data-hid' attributes in meta tags
My website need to be authenticated to search engines for SEO, but they can't be authenticated, which caused by data-n-head and data-hid attributes in meta tags.
I have tried these hooks in nuxt.config.ts:
{
// ...
hooks: {
generate: {
page(page: { html: string }) {
const cheerio = require('cheerio')
const $ = cheerio.load(page.html, { decodeEntities: false })
const attrs = [
'data-n-head-ssr',
'data-n-head',
'data-hid',
'data-vue-ssr-id',
'data-server-rendered'
]
attrs.forEach(value => {
$('*[' + value + ']').removeAttr(value)
})
page.html = $.html()
}
}
}
// ...
}
or this:
{
// ...
hooks: {
'render:route': (_url: URL, result: { html: string }) => {
result.html = result.html
.replace(/ data-n-head=".*?"/gi, '')
.replace(/ data-hid=".*?"/gi, '')
}
}
// ...
}
But twice meta tags are generated, the first is Okay, but the second is repeat, data-n-head and data-hid attributes still in meta tags. I'm so confused!