UNPKG

@inox-tools/content-utils

Version:

Utilities to work with content collections on an Astro project from an integration or library.

38 lines (36 loc) 1.58 kB
import { AstroUserError } from '../chunk-BSNWH4X2.js'; import { tryGetOriginalFancyCollection, isFancyCollection } from '../chunk-HKNNYTOL.js'; import { injectedCollections } from '@it-astro:content/injector'; function injectCollections(collections) { for (const [key, collection] of Object.entries(collections)) { const injectedCollection = injectedCollections[key]; if (injectedCollection === void 0) continue; const originFancyCollection = tryGetOriginalFancyCollection(collection); if (originFancyCollection === null) { throw new AstroUserError( // TODO: Report which integration added the collection. `Content collection "${key}" overrides a collection injected by an integration.`, "Try to use a different collection name." ); } if (!Object.is(originFancyCollection, injectedCollection)) { throw new AstroUserError( // TODO: Report which integration added the collection. `Content collection "${key}" extends from one an injected collection, but overrides a different collection.`, "When extending an injected collection you must not change the collection name." ); } } const combinedCollections = { ...injectedCollections, ...collections }; const resolvedCollections = {}; for (const [key, value] of Object.entries(combinedCollections)) { resolvedCollections[key] = isFancyCollection(value) ? value() : value; } return resolvedCollections; } export { injectCollections }; //# sourceMappingURL=injector.js.map //# sourceMappingURL=injector.js.map