mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
feat(vue-app, vue-renderer): support meta headAttrs
(#4536)
This commit is contained in:
parent
da0a3794ef
commit
99614535b5
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html {{ HTML_ATTRS }}>
|
||||
<head>
|
||||
<head {{ HEAD_ATTRS }}>
|
||||
{{ HEAD }}
|
||||
</head>
|
||||
<body {{ BODY_ATTRS }}>
|
||||
|
@ -282,6 +282,7 @@ export default class VueRenderer {
|
||||
renderTemplate(ssr, opts) {
|
||||
// Fix problem with HTMLPlugin's minify option (#3392)
|
||||
opts.html_attrs = opts.HTML_ATTRS
|
||||
opts.head_attrs = opts.HEAD_ATTRS
|
||||
opts.body_attrs = opts.BODY_ATTRS
|
||||
|
||||
const fn = ssr ? this.context.resources.ssrTemplate : this.context.resources.spaTemplate
|
||||
@ -315,6 +316,7 @@ export default class VueRenderer {
|
||||
if (!this.SSR || spa) {
|
||||
const {
|
||||
HTML_ATTRS,
|
||||
HEAD_ATTRS,
|
||||
BODY_ATTRS,
|
||||
HEAD,
|
||||
BODY_SCRIPTS,
|
||||
@ -325,6 +327,7 @@ export default class VueRenderer {
|
||||
|
||||
const html = this.renderTemplate(false, {
|
||||
HTML_ATTRS,
|
||||
HEAD_ATTRS,
|
||||
BODY_ATTRS,
|
||||
HEAD,
|
||||
APP,
|
||||
@ -382,6 +385,7 @@ export default class VueRenderer {
|
||||
|
||||
const html = this.renderTemplate(true, {
|
||||
HTML_ATTRS: 'data-n-head-ssr ' + m.htmlAttrs.text(),
|
||||
HEAD_ATTRS: m.headAttrs.text(),
|
||||
BODY_ATTRS: m.bodyAttrs.text(),
|
||||
HEAD,
|
||||
APP,
|
||||
|
@ -39,6 +39,7 @@ export default class SPAMetaRenderer {
|
||||
|
||||
meta = {
|
||||
HTML_ATTRS: '',
|
||||
HEAD_ATTRS: '',
|
||||
BODY_ATTRS: '',
|
||||
HEAD: '',
|
||||
BODY_SCRIPTS: ''
|
||||
@ -50,6 +51,9 @@ export default class SPAMetaRenderer {
|
||||
// HTML_ATTRS
|
||||
meta.HTML_ATTRS = m.htmlAttrs.text()
|
||||
|
||||
// HEAD_ATTRS
|
||||
meta.HEAD_ATTRS = m.headAttrs.text()
|
||||
|
||||
// BODY_ATTRS
|
||||
meta.BODY_ATTRS = m.bodyAttrs.text()
|
||||
|
||||
|
3
test/fixtures/meta-attrs/meta-attrs.test.js
vendored
Normal file
3
test/fixtures/meta-attrs/meta-attrs.test.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { buildFixture } from '../../utils/build'
|
||||
|
||||
buildFixture('meta-attrs')
|
15
test/fixtures/meta-attrs/nuxt.config.js
vendored
Normal file
15
test/fixtures/meta-attrs/nuxt.config.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
export default {
|
||||
head: {
|
||||
htmlAttrs: {
|
||||
foo: 'baz'
|
||||
},
|
||||
|
||||
headAttrs: {
|
||||
bar: 'foo'
|
||||
},
|
||||
|
||||
bodyAttrs: {
|
||||
baz: 'bar'
|
||||
}
|
||||
}
|
||||
}
|
23
test/unit/meta-attrs.test.js
Normal file
23
test/unit/meta-attrs.test.js
Normal file
@ -0,0 +1,23 @@
|
||||
import { loadFixture, getPort, Nuxt } from '../utils'
|
||||
|
||||
let nuxt = null
|
||||
|
||||
describe('meta-attrs', () => {
|
||||
beforeAll(async () => {
|
||||
const options = await loadFixture('meta-attrs')
|
||||
nuxt = new Nuxt(options)
|
||||
await nuxt.server.listen(await getPort(), '0.0.0.0')
|
||||
})
|
||||
|
||||
test('/', async () => {
|
||||
const { html } = await nuxt.server.renderRoute('/')
|
||||
expect(html).toContain('<html data-n-head-ssr foo="baz" data-n-head="foo">')
|
||||
expect(html).toContain('<head bar="foo" data-n-head="bar">')
|
||||
expect(html).toContain('<body baz="bar" data-n-head="baz">')
|
||||
})
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
afterAll(async () => {
|
||||
await nuxt.close()
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user