mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
feat: Handle body scripts from vue-meta
This commit is contained in:
parent
4cfc8f5c49
commit
07eab4c643
@ -45,7 +45,8 @@ export default class MetaRenderer {
|
|||||||
meta = {
|
meta = {
|
||||||
HTML_ATTRS: '',
|
HTML_ATTRS: '',
|
||||||
BODY_ATTRS: '',
|
BODY_ATTRS: '',
|
||||||
HEAD: ''
|
HEAD: '',
|
||||||
|
BODY_SCRIPTS: ''
|
||||||
}
|
}
|
||||||
// Get vue-meta context
|
// Get vue-meta context
|
||||||
const m = await this.getMeta(url)
|
const m = await this.getMeta(url)
|
||||||
@ -55,6 +56,8 @@ export default class MetaRenderer {
|
|||||||
meta.BODY_ATTRS = m.bodyAttrs.text()
|
meta.BODY_ATTRS = m.bodyAttrs.text()
|
||||||
// HEAD tags
|
// HEAD tags
|
||||||
meta.HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text()
|
meta.HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text()
|
||||||
|
// BODY_SCRIPTS
|
||||||
|
meta.BODY_SCRIPTS = m.script.text({ body: true })
|
||||||
// Resources Hints
|
// Resources Hints
|
||||||
meta.resourceHints = ''
|
meta.resourceHints = ''
|
||||||
// Resource Hints
|
// Resource Hints
|
||||||
|
@ -488,8 +488,8 @@ export default class Renderer {
|
|||||||
const ENV = this.options.env
|
const ENV = this.options.env
|
||||||
|
|
||||||
if (this.noSSR || spa) {
|
if (this.noSSR || spa) {
|
||||||
const { HTML_ATTRS, BODY_ATTRS, HEAD, resourceHints } = await this.metaRenderer.render(context)
|
const { HTML_ATTRS, BODY_ATTRS, HEAD, BODY_SCRIPTS, resourceHints } = await this.metaRenderer.render(context)
|
||||||
const APP = `<div id="__nuxt">${this.resources.loadingHTML}</div>`
|
const APP = `<div id="__nuxt">${this.resources.loadingHTML}</div>` + BODY_SCRIPTS
|
||||||
|
|
||||||
// Detect 404 errors
|
// Detect 404 errors
|
||||||
if (url.includes(this.options.build.publicPath) || url.includes('__webpack')) {
|
if (url.includes(this.options.build.publicPath) || url.includes('__webpack')) {
|
||||||
@ -528,6 +528,7 @@ export default class Renderer {
|
|||||||
}
|
}
|
||||||
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })};</script>`
|
APP += `<script type="text/javascript">window.__NUXT__=${serialize(context.nuxt, { isJSON: true })};</script>`
|
||||||
APP += context.renderScripts()
|
APP += context.renderScripts()
|
||||||
|
APP += m.script.text({ body: true })
|
||||||
|
|
||||||
HEAD += context.renderStyles()
|
HEAD += context.renderStyles()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user