1
1
/**
2
- * vue-meta v2.2.0
2
+ * vue-meta v2.2.1
3
3
* (c) 2019
4
4
* - Declan de Wet
5
5
* - Sébastien Chopin (@Atinux)
@@ -13,7 +13,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
13
13
14
14
var deepmerge = _interopDefault ( require ( 'deepmerge' ) ) ;
15
15
16
- var version = "2.2.0 " ;
16
+ var version = "2.2.1 " ;
17
17
18
18
// store an id to keep track of DOM updates
19
19
var batchId = null ;
@@ -206,7 +206,7 @@ var hasGlobalWindow = hasGlobalWindowFn();
206
206
207
207
var _global = hasGlobalWindow ? window : global ;
208
208
209
- var console = _global . console = _global . console || { } ;
209
+ var console = _global . console || { } ;
210
210
function warn ( str ) {
211
211
/* istanbul ignore next */
212
212
if ( ! console || ! console . warn ) {
@@ -438,7 +438,8 @@ var tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can hav
438
438
439
439
var tagsWithInnerContent = [ 'noscript' , 'script' , 'style' ] ; // Attributes which are inserted as childNodes instead of HTMLAttribute
440
440
441
- var tagAttributeAsInnerContent = [ 'innerHTML' , 'cssText' , 'json' ] ; // Attributes which should be added with data- prefix
441
+ var tagAttributeAsInnerContent = [ 'innerHTML' , 'cssText' , 'json' ] ;
442
+ var tagProperties = [ 'once' , 'template' ] ; // Attributes which should be added with data- prefix
442
443
443
444
var commonDataAttributes = [ 'body' , 'pbody' ] ; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
444
445
@@ -625,13 +626,23 @@ function applyTemplate(_ref, headObject, template, chunk) {
625
626
metaTemplateKeyName = _ref . metaTemplateKeyName ,
626
627
contentKeyName = _ref . contentKeyName ;
627
628
628
- if ( isUndefined ( template ) ) {
629
+ if ( template === true || headObject [ metaTemplateKeyName ] === true ) {
630
+ // abort, template was already applied
631
+ return false ;
632
+ }
633
+
634
+ if ( isUndefined ( template ) && headObject [ metaTemplateKeyName ] ) {
629
635
template = headObject [ metaTemplateKeyName ] ;
630
- delete headObject [ metaTemplateKeyName ] ;
636
+ headObject [ metaTemplateKeyName ] = true ;
631
637
} // return early if no template defined
632
638
633
639
634
640
if ( ! template ) {
641
+ // cleanup faulty template properties
642
+ if ( headObject . hasOwnProperty ( metaTemplateKeyName ) ) {
643
+ delete headObject [ metaTemplateKeyName ] ;
644
+ }
645
+
635
646
return false ;
636
647
}
637
648
@@ -652,6 +663,11 @@ function _arrayMerge(_ref, target, source) {
652
663
// but we check for a `vmid` property on each object in the array
653
664
// using an O(1) lookup associative array exploit
654
665
var destination = [ ] ;
666
+
667
+ if ( ! target . length && ! source . length ) {
668
+ return destination ;
669
+ }
670
+
655
671
target . forEach ( function ( targetItem , targetIndex ) {
656
672
// no tagID so no need to check for duplicity
657
673
if ( ! targetItem [ tagIDKeyName ] ) {
@@ -702,9 +718,14 @@ function _arrayMerge(_ref, target, source) {
702
718
component : component ,
703
719
metaTemplateKeyName : metaTemplateKeyName ,
704
720
contentKeyName : contentKeyName
705
- } , sourceItem , targetTemplate ) ;
706
- } else if ( ! sourceItem [ contentKeyName ] ) {
707
- // use child template and parent content
721
+ } , sourceItem , targetTemplate ) ; // set template to true to indicate template was already applied
722
+
723
+ sourceItem . template = true ;
724
+ return ;
725
+ }
726
+
727
+ if ( ! sourceItem [ contentKeyName ] ) {
728
+ // use parent content and child template
708
729
applyTemplate ( {
709
730
component : component ,
710
731
metaTemplateKeyName : metaTemplateKeyName ,
@@ -770,9 +791,7 @@ function getComponentOption() {
770
791
var options = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ;
771
792
var component = arguments . length > 1 ? arguments [ 1 ] : undefined ;
772
793
var result = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
773
- var keyName = options . keyName ,
774
- metaTemplateKeyName = options . metaTemplateKeyName ,
775
- tagIDKeyName = options . tagIDKeyName ;
794
+ var keyName = options . keyName ;
776
795
var $options = component . $options ,
777
796
$children = component . $children ;
778
797
@@ -810,22 +829,6 @@ function getComponentOption() {
810
829
} ) ;
811
830
}
812
831
813
- if ( metaTemplateKeyName && result . meta ) {
814
- // apply templates if needed
815
- result . meta . forEach ( function ( metaObject ) {
816
- return applyTemplate ( options , metaObject ) ;
817
- } ) ; // remove meta items with duplicate vmid's
818
-
819
- result . meta = result . meta . filter ( function ( metaItem , index , arr ) {
820
- return ( // keep meta item if it doesnt has a vmid
821
- ! metaItem . hasOwnProperty ( tagIDKeyName ) || // or if it's the first item in the array with this vmid
822
- index === findIndex ( arr , function ( item ) {
823
- return item [ tagIDKeyName ] === metaItem [ tagIDKeyName ] ;
824
- } )
825
- ) ;
826
- } ) ;
827
- }
828
-
829
832
return result ;
830
833
}
831
834
@@ -842,9 +845,9 @@ function getMetaInfo() {
842
845
var info = arguments . length > 1 ? arguments [ 1 ] : undefined ;
843
846
var escapeSequences = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : [ ] ;
844
847
var component = arguments . length > 3 ? arguments [ 3 ] : undefined ;
845
-
846
- // Remove all "template" tags from meta
848
+ var tagIDKeyName = options . tagIDKeyName ; // Remove all "template" tags from meta
847
849
// backup the title chunk in case user wants access to it
850
+
848
851
if ( info . title ) {
849
852
info . titleChunk = info . title ;
850
853
} // replace title with populated template
@@ -863,6 +866,26 @@ function getMetaInfo() {
863
866
info . base = Object . keys ( info . base ) . length ? [ info . base ] : [ ] ;
864
867
}
865
868
869
+ if ( info . meta ) {
870
+ // remove meta items with duplicate vmid's
871
+ info . meta = info . meta . filter ( function ( metaItem , index , arr ) {
872
+ var hasVmid = metaItem . hasOwnProperty ( tagIDKeyName ) ;
873
+
874
+ if ( ! hasVmid ) {
875
+ return true ;
876
+ }
877
+
878
+ var isFirstItemForVmid = index === findIndex ( arr , function ( item ) {
879
+ return item [ tagIDKeyName ] === metaItem [ tagIDKeyName ] ;
880
+ } ) ;
881
+ return isFirstItemForVmid ;
882
+ } ) ; // apply templates if needed
883
+
884
+ info . meta . forEach ( function ( metaObject ) {
885
+ return applyTemplate ( options , metaObject ) ;
886
+ } ) ;
887
+ }
888
+
866
889
return escapeMetaInfo ( options , info , escapeSequences ) ;
867
890
}
868
891
@@ -1119,7 +1142,7 @@ function updateTag(appId) {
1119
1142
1120
1143
var _loop = function _loop ( attr ) {
1121
1144
/* istanbul ignore next */
1122
- if ( ! tag . hasOwnProperty ( attr ) ) {
1145
+ if ( ! tag . hasOwnProperty ( attr ) || includes ( tagProperties , attr ) ) {
1123
1146
return "continue" ;
1124
1147
}
1125
1148
@@ -1436,7 +1459,7 @@ function tagGenerator() {
1436
1459
1437
1460
for ( var attr in tag ) {
1438
1461
// these attributes are treated as children on the tag
1439
- if ( tagAttributeAsInnerContent . includes ( attr ) || attr === 'once' ) {
1462
+ if ( tagAttributeAsInnerContent . includes ( attr ) || tagProperties . includes ( attr ) ) {
1440
1463
continue ;
1441
1464
}
1442
1465
0 commit comments