From 915fedfb7f5cd852292576397c37b42bd7c55191 Mon Sep 17 00:00:00 2001 From: pimlie Date: Fri, 8 Mar 2019 15:25:57 +0100 Subject: [PATCH] feat: child can indicate parent vmid to be removed (resolves: #288) --- src/shared/merge.js | 7 ++++++ test/getMetaInfo.test.js | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/shared/merge.js b/src/shared/merge.js index fcbbe229..f0af9c35 100644 --- a/src/shared/merge.js +++ b/src/shared/merge.js @@ -25,6 +25,13 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte return } + // if source specifies null as content then ignore both the target as the source + if (sourceItem[contentKeyName] === null || sourceItem.innerHTML === null) { + // remove current index from source array so its not concatenated to destination below + source.splice(sourceIndex, 1) + return + } + // we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem // now we only need to check if the target has a template to combine it with the source const targetTemplate = targetItem[metaTemplateKeyName] diff --git a/test/getMetaInfo.test.js b/test/getMetaInfo.test.js index d6ab3ec6..b496e853 100644 --- a/test/getMetaInfo.test.js +++ b/test/getMetaInfo.test.js @@ -671,4 +671,52 @@ describe('getMetaInfo', () => { __dangerouslyDisableSanitizersByTagID: {} }) }) + + test('child can indicate to remove parent vmids', () => { + Vue.component('merge-child', { + render: h => h('div'), + metaInfo: { + title: 'Hi', + meta: [ + { + vmid: 'og:title', + content: null + } + ] + } + }) + + const component = new Vue({ + metaInfo: { + title: 'Hello', + meta: [ + { + vmid: 'og:title', + property: 'og:title', + content: 'Test title', + template: chunk => `${chunk} - My page` + } + ] + }, + el: document.createElement('div'), + render: h => h('div', null, [h('merge-child')]) + }) + + expect(getMetaInfo(component)).toEqual({ + title: 'Hi', + titleChunk: 'Hi', + titleTemplate: '%s', + htmlAttrs: {}, + headAttrs: {}, + bodyAttrs: {}, + meta: [], + base: [], + link: [], + style: [], + script: [], + noscript: [], + __dangerouslyDisableSanitizers: [], + __dangerouslyDisableSanitizersByTagID: {} + }) + }) })