mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 18:00:35 +03:00
fix: support falsy values in eg body attributes (fix: #535)
This commit is contained in:
@@ -20,6 +20,9 @@ new Vue({
|
|||||||
headAttrs: {
|
headAttrs: {
|
||||||
test: true
|
test: true
|
||||||
},
|
},
|
||||||
|
bodyAttrs: {
|
||||||
|
tabIndex: 0
|
||||||
|
},
|
||||||
meta: [
|
meta: [
|
||||||
{ name: 'description', content: 'Hello', vmid: 'test' }
|
{ name: 'description', content: 'Hello', vmid: 'test' }
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
|
|||||||
// remove attributes from the map
|
// remove attributes from the map
|
||||||
// which have been removed for this appId
|
// which have been removed for this appId
|
||||||
for (const attr in data) {
|
for (const attr in data) {
|
||||||
if (data[attr] && appId in data[attr]) {
|
if (data[attr] !== undefined && appId in data[attr]) {
|
||||||
toUpdate.push(attr)
|
toUpdate.push(attr)
|
||||||
|
|
||||||
if (!attrs[attr]) {
|
if (!attrs[attr]) {
|
||||||
@@ -43,7 +43,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
|
|||||||
if (!attrData || attrData[appId] !== attrs[attr]) {
|
if (!attrData || attrData[appId] !== attrs[attr]) {
|
||||||
toUpdate.push(attr)
|
toUpdate.push(attr)
|
||||||
|
|
||||||
if (attrs[attr]) {
|
if (attrs[attr] !== undefined) {
|
||||||
data[attr] = data[attr] || {}
|
data[attr] = data[attr] || {}
|
||||||
data[attr][appId] = attrs[attr]
|
data[attr][appId] = attrs[attr]
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ export default function updateAttribute (appId, options, type, attrs, tag) {
|
|||||||
if (attrValues.length) {
|
if (attrValues.length) {
|
||||||
const attrValue = includes(booleanHtmlAttributes, attr) && attrValues.some(Boolean)
|
const attrValue = includes(booleanHtmlAttributes, attr) && attrValues.some(Boolean)
|
||||||
? ''
|
? ''
|
||||||
: attrValues.filter(Boolean).join(' ')
|
: attrValues.filter(v => v !== undefined).join(' ')
|
||||||
|
|
||||||
tag.setAttribute(attr, attrValue)
|
tag.setAttribute(attr, attrValue)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -270,8 +270,8 @@ const metaInfoData = {
|
|||||||
},
|
},
|
||||||
bodyAttrs: {
|
bodyAttrs: {
|
||||||
add: {
|
add: {
|
||||||
data: { foo: 'bar', fizz: ['fuzz', 'fozz'] },
|
data: { foo: 'bar', fizz: ['fuzz', 'fozz'], falsy: 0 },
|
||||||
expect: ['<body foo="bar" fizz="fuzz fozz" data-vue-meta="%7B%22foo%22:%7B%22ssr%22:%22bar%22%7D,%22fizz%22:%7B%22ssr%22:%5B%22fuzz%22,%22fozz%22%5D%7D%7D">'],
|
expect: ['<body foo="bar" fizz="fuzz fozz" falsy="0" data-vue-meta="%7B%22foo%22:%7B%22ssr%22:%22bar%22%7D,%22fizz%22:%7B%22ssr%22:%5B%22fuzz%22,%22fozz%22%5D%7D,%22falsy%22:%7B%22ssr%22:0%7D%7D">'],
|
||||||
test (side, defaultTest) {
|
test (side, defaultTest) {
|
||||||
return () => {
|
return () => {
|
||||||
if (side === 'client') {
|
if (side === 'client') {
|
||||||
@@ -284,7 +284,8 @@ const metaInfoData = {
|
|||||||
expect(attributeMap).toEqual({
|
expect(attributeMap).toEqual({
|
||||||
bodyAttrs: {
|
bodyAttrs: {
|
||||||
foo: { ssr: 'bar' },
|
foo: { ssr: 'bar' },
|
||||||
fizz: { ssr: ['fuzz', 'fozz'] }
|
fizz: { ssr: ['fuzz', 'fozz'] },
|
||||||
|
falsy: { ssr: 0 }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -298,7 +299,7 @@ const metaInfoData = {
|
|||||||
return () => {
|
return () => {
|
||||||
defaultTest()
|
defaultTest()
|
||||||
|
|
||||||
expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {} } })
|
expect(attributeMap).toEqual({ bodyAttrs: { foo: { ssr: 'baz' }, fizz: {}, falsy: {} } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -309,7 +310,7 @@ const metaInfoData = {
|
|||||||
return () => {
|
return () => {
|
||||||
defaultTest()
|
defaultTest()
|
||||||
|
|
||||||
expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {} } })
|
expect(attributeMap).toEqual({ bodyAttrs: { foo: {}, fizz: {}, falsy: {} } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user