mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-25 02:50:33 +03:00
Merge pull request #282 from manniL/test-multiple-attrs-same
feat: dedupe meta objects by VMID
This commit is contained in:
Generated
+10
@@ -6609,6 +6609,16 @@
|
|||||||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
|
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"lodash.uniqby": {
|
||||||
|
"version": "4.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz",
|
||||||
|
"integrity": "sha1-2ZwHpmnp5tJOE2Lf4mbGdhavEwI="
|
||||||
|
},
|
||||||
|
"lodash.uniqueid": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.uniqueid/-/lodash.uniqueid-4.0.1.tgz",
|
||||||
|
"integrity": "sha1-MmjyanyI5PSxdY1nknGBTjH6WyY="
|
||||||
|
},
|
||||||
"log-symbols": {
|
"log-symbols": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"deepmerge": "^2.2.1",
|
"deepmerge": "^2.2.1",
|
||||||
"lodash.isplainobject": "^4.0.6",
|
"lodash.isplainobject": "^4.0.6",
|
||||||
|
"lodash.uniqby": "^4.7.0",
|
||||||
|
"lodash.uniqueid": "^4.0.1",
|
||||||
"object-assign": "^4.1.1"
|
"object-assign": "^4.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import deepmerge from 'deepmerge'
|
import deepmerge from 'deepmerge'
|
||||||
|
import uniqBy from 'lodash.uniqby'
|
||||||
|
import uniqueId from 'lodash.uniqueid'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the `opts.option` $option value of the given `opts.component`.
|
* Returns the `opts.option` $option value of the given `opts.component`.
|
||||||
@@ -15,7 +17,7 @@ import deepmerge from 'deepmerge'
|
|||||||
* @return {Object} result - final aggregated result
|
* @return {Object} result - final aggregated result
|
||||||
*/
|
*/
|
||||||
export default function getComponentOption (opts, result = {}) {
|
export default function getComponentOption (opts, result = {}) {
|
||||||
const { component, option, deep, arrayMerge, metaTemplateKeyName, contentKeyName } = opts
|
const { component, option, deep, arrayMerge, metaTemplateKeyName, tagIDKeyName, contentKeyName } = opts
|
||||||
const { $options } = component
|
const { $options } = component
|
||||||
|
|
||||||
if (component._inactive) return result
|
if (component._inactive) return result
|
||||||
@@ -64,6 +66,10 @@ export default function getComponentOption (opts, result = {}) {
|
|||||||
|
|
||||||
return metaObject
|
return metaObject
|
||||||
})
|
})
|
||||||
|
result.meta = uniqBy(
|
||||||
|
result.meta.reverse(),
|
||||||
|
metaObject => metaObject.hasOwnProperty(tagIDKeyName) ? metaObject[tagIDKeyName] : uniqueId()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ export default function _getMetaInfo (options = {}) {
|
|||||||
option: keyName,
|
option: keyName,
|
||||||
deep: true,
|
deep: true,
|
||||||
metaTemplateKeyName,
|
metaTemplateKeyName,
|
||||||
|
tagIDKeyName,
|
||||||
contentKeyName,
|
contentKeyName,
|
||||||
arrayMerge (target, source) {
|
arrayMerge (target, source) {
|
||||||
// we concat the arrays without merging objects contained in,
|
// we concat the arrays without merging objects contained in,
|
||||||
|
|||||||
@@ -75,6 +75,47 @@ describe('getMetaInfo', () => {
|
|||||||
__dangerouslyDisableSanitizersByTagID: {}
|
__dangerouslyDisableSanitizersByTagID: {}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
it('removes duplicate metaInfo in same component', () => {
|
||||||
|
component = new Vue({
|
||||||
|
metaInfo: {
|
||||||
|
title: 'Hello',
|
||||||
|
meta: [
|
||||||
|
{
|
||||||
|
vmid: 'a',
|
||||||
|
property: 'a',
|
||||||
|
content: 'a'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vmid: 'a',
|
||||||
|
property: 'a',
|
||||||
|
content: 'b'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(getMetaInfo(component)).to.eql({
|
||||||
|
title: 'Hello',
|
||||||
|
titleChunk: 'Hello',
|
||||||
|
titleTemplate: '%s',
|
||||||
|
htmlAttrs: {},
|
||||||
|
headAttrs: {},
|
||||||
|
bodyAttrs: {},
|
||||||
|
meta: [
|
||||||
|
{
|
||||||
|
vmid: 'a',
|
||||||
|
property: 'a',
|
||||||
|
content: 'b'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
base: [],
|
||||||
|
link: [],
|
||||||
|
style: [],
|
||||||
|
script: [],
|
||||||
|
noscript: [],
|
||||||
|
__dangerouslyDisableSanitizers: [],
|
||||||
|
__dangerouslyDisableSanitizersByTagID: {}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('properly uses string titleTemplates', () => {
|
it('properly uses string titleTemplates', () => {
|
||||||
component = new Vue({
|
component = new Vue({
|
||||||
|
|||||||
Reference in New Issue
Block a user