const metaInfoUtils = {
  metaInfoMerge: function(metaInfo, metaInfoToAdd) {
    if(metaInfoToAdd == null) return
    //
    if (metaInfo == null) {
      metaInfo = metaInfoToAdd
    } else {
      if (metaInfo.meta == null) {
        metaInfo.meta = metaInfoToAdd.meta
      } else if (metaInfoToAdd.meta != null && metaInfoToAdd.meta.length > 0) {
        let metaInfoMetas = []
        metaInfo.meta.forEach(meta => {
          metaInfoMetas.push(JSON.stringify(meta))
        })
        metaInfoToAdd.meta.forEach(meta => {
          if(metaInfoMetas.indexOf(JSON.stringify(meta) == -1)) {
            metaInfo.meta.push(meta)
          }
        })
      }
      //
      if (metaInfo.script == null) {
        metaInfo.script = metaInfoToAdd.script
      } else if (metaInfoToAdd.script != null && metaInfoToAdd.script.length > 0) {
        let metaInfoScripts = []
        metaInfo.script.forEach(script => {
          metaInfoScripts.push(JSON.stringify(script))
        })
        metaInfoToAdd.script.forEach(script => {
          if (metaInfoScripts.indexOf(JSON.stringify(script)) == -1) {
            metaInfo.script.push(script)
          }
        })
      }
      //
    }
    return metaInfo
  }
}
export default metaInfoUtils