UNPKG

gatsby-source-prismic

Version:

Gatsby source plugin for building websites using Prismic as a data source

41 lines (40 loc) 1.59 kB
import { fmtLog } from "./fmtLog.js"; import { normalizeDocument } from "./normalizeDocument.js"; import { pascalCase } from "./pascalCase.js"; const createDocumentNodes = async (args) => { const alreadyWarnedAboutMissingCustomTypeModels = []; await Promise.all(args.documents.map(async (document) => { const model = args.customTypeModels.find((customTypeModel) => { return customTypeModel.id === document.type; }); if (model) { const normalizedDocument = await normalizeDocument({ document, model, pluginOptions: args.pluginOptions, gatsbyNodeArgs: args.gatsbyNodeArgs, sharedSliceModels: args.sharedSliceModels }); const node = { ...normalizedDocument, id: args.gatsbyNodeArgs.createNodeId(document.id), prismicId: document.id, raw: document, internal: { type: pascalCase("Prismic", args.pluginOptions.typePrefix, document.type), contentDigest: args.gatsbyNodeArgs.createContentDigest(document) } }; args.gatsbyNodeArgs.actions.createNode(node); } else { if (!alreadyWarnedAboutMissingCustomTypeModels.includes(document.type)) { alreadyWarnedAboutMissingCustomTypeModels.push(document.type); args.gatsbyNodeArgs.reporter.warn(fmtLog(args.pluginOptions.repositoryName, `A "${document.type}" Custom Type model was not provided to the plugin. All documents of this type will not be queryable.`)); } } })); }; export { createDocumentNodes }; //# sourceMappingURL=createDocumentNodes.js.map