11import { EntryModel } from "." ;
22
3- export function addTags ( entry : EntryModel , contentTypeUid : string , tagsAsObject : boolean , locale : string = 'en-us' ) : void {
4- entry [ "$" ] = getTag ( entry , `${ contentTypeUid } .${ entry . uid } .${ locale } ` , tagsAsObject , locale )
3+ export function addTags ( entry : EntryModel , contentTypeUid : string , tagsAsObject : boolean , locale : string = 'en-us' ) : void {
4+ if ( entry )
5+ entry [ "$" ] = getTag ( entry , `${ contentTypeUid } .${ entry . uid } .${ locale } ` , tagsAsObject , locale )
56}
67
78function getTag ( content : object , prefix : string , tagsAsObject : boolean , locale : string ) : object {
@@ -11,7 +12,7 @@ function getTag(content: object, prefix: string, tagsAsObject: boolean, locale:
1112 case "object" :
1213 if ( Array . isArray ( value ) ) {
1314 value . forEach ( ( obj , index ) => {
14- if ( obj . _content_type_uid !== undefined && obj . uid !== undefined ) {
15+ if ( ( typeof obj !== 'undefined' || obj !== null ) && obj . _content_type_uid !== undefined && obj . uid !== undefined ) {
1516 value [ index ] [ '$' ] = getTag ( obj , `${ obj . _content_type_uid } .${ obj . uid } .${ obj . locale || locale } ` , tagsAsObject , locale )
1617 } else {
1718 if ( typeof obj === "object" ) {
@@ -22,7 +23,9 @@ function getTag(content: object, prefix: string, tagsAsObject: boolean, locale:
2223 }
2324 } )
2425 } else {
25- value [ "$" ] = getTag ( value , `${ prefix } .${ key } ` , tagsAsObject , locale )
26+ if ( value ) {
27+ value [ "$" ] = getTag ( value , `${ prefix } .${ key } ` , tagsAsObject , locale )
28+ }
2629 }
2730 break ;
2831 default :
0 commit comments