2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-24 04:40:34 +03:00

fix: Handle body attribute with valid W3C HTML

This commit is contained in:
Atinux
2017-11-06 12:32:43 +01:00
parent 8ac7ecccaa
commit 885a3f5fdf
4 changed files with 6 additions and 9 deletions
+2 -2
View File
@@ -47,7 +47,7 @@ export default function _updateTags (options = {}) {
} else { } else {
newElement.appendChild(document.createTextNode(tag.cssText)) newElement.appendChild(document.createTextNode(tag.cssText))
} }
} else if (attr === options.tagIDKeyName) { } else if ([options.tagIDKeyName, 'body'].includes(attr)) {
const _attr = `data-${attr}` const _attr = `data-${attr}`
const value = (typeof tag[attr] === 'undefined') ? '' : tag[attr] const value = (typeof tag[attr] === 'undefined') ? '' : tag[attr]
newElement.setAttribute(_attr, value) newElement.setAttribute(_attr, value)
@@ -74,7 +74,7 @@ export default function _updateTags (options = {}) {
const oldTags = oldHeadTags.concat(oldBodyTags) const oldTags = oldHeadTags.concat(oldBodyTags)
oldTags.forEach((tag) => tag.parentNode.removeChild(tag)) oldTags.forEach((tag) => tag.parentNode.removeChild(tag))
newTags.forEach((tag) => { newTags.forEach((tag) => {
if (tag.getAttribute('body') === 'true') { if (tag.getAttribute('data-body') === 'true') {
bodyTag.appendChild(tag) bodyTag.appendChild(tag)
} else { } else {
headTag.appendChild(tag) headTag.appendChild(tag)
+2 -2
View File
@@ -10,7 +10,7 @@ export default function _tagGenerator (options = {}) {
*/ */
return function tagGenerator (type, tags) { return function tagGenerator (type, tags) {
return { return {
text ({body = false} = {}) { text ({ body = false } = {}) {
// build a string containing all tags of this type // build a string containing all tags of this type
return tags.reduce((tagsStr, tag) => { return tags.reduce((tagsStr, tag) => {
if (!!tag.body !== body) return tagsStr if (!!tag.body !== body) return tagsStr
@@ -24,7 +24,7 @@ export default function _tagGenerator (options = {}) {
return attrsStr return attrsStr
// these form the attribute list for this tag // these form the attribute list for this tag
default: default:
if (attr === options.tagIDKeyName) { if ([options.tagIDKeyName, 'body'].includes(attr)) {
return `${attrsStr} data-${attr}="${tag[attr]}"` return `${attrsStr} data-${attr}="${tag[attr]}"`
} }
return typeof tag[attr] === 'undefined' return typeof tag[attr] === 'undefined'
+1 -4
View File
@@ -31,10 +31,7 @@ export default function getComponentOption (opts, result = {}) {
if (typeof data === 'object') { if (typeof data === 'object') {
// merge with existing options // merge with existing options
result = deepmerge(result, data, { result = deepmerge(result, data, { arrayMerge })
clone: true,
arrayMerge
})
} else { } else {
result = data result = data
} }
+1 -1
View File
@@ -52,7 +52,7 @@ export default function _getMetaInfo (options = {}) {
option: keyName, option: keyName,
deep: true, deep: true,
arrayMerge (target, source) { arrayMerge (target, source) {
// we concat the arrays without merging objects contained therein, // we concat the arrays without merging objects contained in,
// but we check for a `vmid` property on each object in the array // but we check for a `vmid` property on each object in the array
// using an O(1) lookup associative array exploit // using an O(1) lookup associative array exploit
// note the use of "for in" - we are looping through arrays here, not // note the use of "for in" - we are looping through arrays here, not