text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  
  var React = _interopRequireWildcard(require("react"));
  
  var _gatsby = require("gatsby");
  
  var _common = require("./common.js");
  
  var _getManifestPathname = _interopRequireDefault(require("./get-manifest-pathname"));
  
  // TODO: remove for v3
  var withPrefix = _gatsby.withAssetPrefix || _gatsby.withPrefix;
  
  exports.onRenderBody = function (_ref, _ref2) {
    var setHeadComponents = _ref.setHeadComponents,
        _ref$pathname = _ref.pathname,
        pathname = _ref$pathname === void 0 ? "/" : _ref$pathname;
    var localize = _ref2.localize,
        legacy = _ref2.legacy,
        cacheBusting = _ref2.cache_busting_mode,
        cacheDigest = _ref2.cacheDigest,
        icon = _ref2.icon,
        pluginIcons = _ref2.icons,
        insertFaviconLinkTag = _ref2.include_favicon,
        insertMetaTag = _ref2.theme_color_in_head,
        themeColor = _ref2.theme_color,
        _ref2$crossOrigin = _ref2.crossOrigin,
        crossOrigin = _ref2$crossOrigin === void 0 ? "anonymous" : _ref2$crossOrigin;
    // We use this to build a final array to pass as the argument to setHeadComponents at the end of onRenderBody.
    var headComponents = [];
    var srcIconExists = !!icon;
    var icons = pluginIcons || _common.defaultIcons;
    var manifestFileName = (0, _getManifestPathname.default)(pathname, localize); // If icons were generated, also add a favicon link.
  
    if (srcIconExists) {
      if (insertFaviconLinkTag) {
        _common.favicons.forEach(function (favicon) {
          headComponents.push( /*#__PURE__*/React.createElement("link", {
            key: "gatsby-plugin-manifest-icon-link-png",
            rel: "icon",
            href: withPrefix((0, _common.addDigestToPath)(favicon.src, cacheDigest, cacheBusting)),
            type: "image/png"
          }));
        });
  
        if (icon !== null && icon !== void 0 && icon.endsWith(".svg")) {
          headComponents.push( /*#__PURE__*/React.createElement("link", {
            key: "gatsby-plugin-manifest-icon-link-svg",
            rel: "icon",
            href: withPrefix((0, _common.addDigestToPath)("favicon.svg", cacheDigest, cacheBusting)),
            type: "image/svg+xml"
          }));
        }
      }
    } // Add manifest link tag.
  
  
    headComponents.push( /*#__PURE__*/React.createElement("link", {
      key: "gatsby-plugin-manifest-link",
      rel: "manifest",
      href: (0, _gatsby.withPrefix)("/" + manifestFileName),
      crossOrigin: crossOrigin
    })); // The user has an option to opt out of the theme_color meta tag being inserted into the head.
  
    if (themeColor && insertMetaTag) {
      headComponents.push( /*#__PURE__*/React.createElement("meta", {
        key: "gatsby-plugin-manifest-meta",
        name: "theme-color",
        content: themeColor
      }));
    }
  
    if (legacy) {
      icons.forEach(function (icon) {
        headComponents.push( /*#__PURE__*/React.createElement("link", {
          key: "gatsby-plugin-manifest-apple-touch-icon-" + icon.sizes,
          rel: "apple-touch-icon",
          sizes: icon.sizes,
          href: withPrefix((0, _common.addDigestToPath)(icon.src, cacheDigest, srcIconExists ? cacheBusting : "none"))
        }));
      });
    }
  
    setHeadComponents(headComponents);
    return true;
  };