gatsby-source-prismic
Version:
Gatsby source plugin for building websites using Prismic as a data source
41 lines (40 loc) • 1.74 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const fmtLog = require("./fmtLog.cjs");
const normalizeDocument = require("./normalizeDocument.cjs");
const pascalCase = require("./pascalCase.cjs");
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.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.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.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.`));
}
}
}));
};
exports.createDocumentNodes = createDocumentNodes;
//# sourceMappingURL=createDocumentNodes.cjs.map
;