mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-18 02:20:34 +03:00
feat: attr keys can have array values (resolves #231)
This commit is contained in:
committed by
Alexander Lichter
parent
6e18a7d54a
commit
01edc8c242
@@ -1,3 +1,5 @@
|
||||
import isArray from '../../shared/isArray'
|
||||
|
||||
/**
|
||||
* Updates the document's html tag attributes
|
||||
*
|
||||
@@ -12,8 +14,9 @@ export default function updateAttribute({ attribute } = {}, attrs, tag) {
|
||||
const keepIndexes = []
|
||||
for (const attr in attrs) {
|
||||
if (attrs.hasOwnProperty(attr)) {
|
||||
const value = attrs[attr] || ''
|
||||
tag.setAttribute(attr, value)
|
||||
const value = isArray(attrs[attr]) ? attrs[attr].join(' ') : attrs[attr]
|
||||
|
||||
tag.setAttribute(attr, value || '')
|
||||
|
||||
if (!vueMetaAttrs.includes(attr)) {
|
||||
vueMetaAttrs.push(attr)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { booleanHtmlAttributes } from '../../shared/constants'
|
||||
import { isUndefined } from '../../shared/typeof'
|
||||
import isArray from '../../shared/isArray'
|
||||
|
||||
/**
|
||||
* Generates tag attributes for use on the server.
|
||||
@@ -20,7 +21,7 @@ export default function attributeGenerator({ attribute } = {}, type, data) {
|
||||
|
||||
attributeStr += isUndefined(data[attr]) || booleanHtmlAttributes.includes(attr)
|
||||
? attr
|
||||
: `${attr}="${data[attr]}"`
|
||||
: `${attr}="${isArray(data[attr]) ? data[attr].join(' ') : data[attr]}"`
|
||||
|
||||
attributeStr += ' '
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ export default function escape(info, { tagIDKeyName }, escapeSequences = []) {
|
||||
if (isString(value)) {
|
||||
escaped[key] = escapeSequences.reduce((val, [v, r]) => val.replace(v, r), value)
|
||||
} else if (isArray(value)) {
|
||||
escaped[key] = value.map(v => escape(v, { tagIDKeyName }, escapeSequences))
|
||||
escaped[key] = value.map((v) => {
|
||||
return isObject(v)
|
||||
? escape(v, { tagIDKeyName }, escapeSequences)
|
||||
: escapeSequences.reduce((val, [v, r]) => val.replace(v, r), v)
|
||||
})
|
||||
} else if (isObject(value)) {
|
||||
escaped[key] = escape(value, { tagIDKeyName }, escapeSequences)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user