UNPKG

gatsby-source-sanity

Version:

Gatsby source plugin for building websites using Sanity.io as a backend.

63 lines 2.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var package_json_1 = require("gatsby/package.json"); var semver_1 = require("semver"); var debug_1 = __importDefault(require("../debug")); var warnOnceForNoSupport; var warnOnceToUpgradeGatsby; var GATSBY_VERSION_MANIFEST_V2 = "4.3.0"; var gatsbyVersion = package_json_1.version; var gatsbyVersionIsPrerelease = (function () { try { return (0, semver_1.prerelease)(gatsbyVersion); } catch (error) { return null; } })(); var shouldUpgradeGatsbyVersion = (function () { try { return (0, semver_1.lt)(gatsbyVersion, GATSBY_VERSION_MANIFEST_V2) && !gatsbyVersionIsPrerelease; } catch (error) { return true; } })(); function createNodeManifest(actions, args, node, publishedId) { try { var unstable_createNodeManifest = actions.unstable_createNodeManifest; var getNode = args.getNode; var type = node.internal.type; var autogeneratedTypes = ['SanityFileAsset', 'SanityImageAsset']; var createNodeManifestIsSupported = typeof unstable_createNodeManifest === 'function'; var nodeTypeNeedsManifest = autogeneratedTypes.includes(type) === false; var shouldCreateNodeManifest = createNodeManifestIsSupported && nodeTypeNeedsManifest; if (shouldCreateNodeManifest) { if (shouldUpgradeGatsbyVersion && !warnOnceToUpgradeGatsby) { console.warn("Your site is doing more work than it needs to for Preview, upgrade to Gatsby ^".concat(GATSBY_VERSION_MANIFEST_V2, " for better performance")); warnOnceToUpgradeGatsby = true; } var updatedAt = new Date(node._updatedAt || Date.now()); var nodeForManifest = getNode(node.id); var manifestId = "".concat(publishedId, "-").concat(updatedAt.toISOString()); unstable_createNodeManifest({ manifestId: manifestId, node: nodeForManifest, updatedAtUTC: updatedAt.toUTCString(), }); } else if (!createNodeManifestIsSupported && !warnOnceForNoSupport) { args.reporter.warn("Sanity: Your version of Gatsby core doesn't support Content Sync (via the unstable_createNodeManifest action). Please upgrade to the latest version to use Content Sync in your site."); warnOnceForNoSupport = true; } } catch (e) { var result = e.message; (0, debug_1.default)("Cannot create node manifest", result); } } exports.default = createNodeManifest; //# sourceMappingURL=createNodeManifest.js.map