function configHTMLContent()

in packages/build-plugin-lce/src/common/htmlInjection.js [146:185]


function configHTMLContent(htmlInjection, entryKey) {
  let storage = htmlContentStorage;
  if (entryKey) {
    multiHTMLContentStorage[entryKey] = cloneDeep(htmlContentStorage);
    storage = multiHTMLContentStorage[entryKey];
  }
  Object.keys(htmlInjection).forEach((optionKey) => {
    if (HTML_POSITIONS[optionKey]) {
      const { type } = HTML_POSITIONS[optionKey];
      const value = htmlInjection[optionKey];
      if (type === 'array') {
        const newValue = [];
        // overwrite content by tagId / unique tag
        value.forEach((tagInfo) => {
          const { tagId, tag } = tagInfo;
          let index = -1;
          if (tag === 'title') {
            index = (storage[optionKey] || []).findIndex((item) => item.tag === tag);
          } else if (tagId) {
            index = (storage[optionKey] || []).findIndex((item) => item.tagId === tagId);
          }

          if (index > -1) {
            storage[optionKey][index] = tagInfo;
          } else {
            newValue.push(tagInfo);
          }
        });
        storage[optionKey] = (storage[optionKey] || []).concat(newValue);
      } else if (type === 'object') {
        storage[optionKey] = {
          ...(storage[optionKey] || {}),
          ...value,
        };
      } else {
        storage[optionKey] = value;
      }
    }
  });
}