UNPKG

@botonic/plugin-contentful

Version:

Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet

31 lines 1.23 kB
import * as cms from '../../cms'; import { CmsException, ContentType } from '../../cms'; import { TopContentType } from '../../cms/cms'; import { isOfType } from '../../util/enums'; import { ContentfulEntryUtils } from '../delivery-utils'; export function getTargetCallback(target, context) { const model = ContentfulEntryUtils.getContentModel(target); try { switch (model) { case ContentType.URL: { const urlFields = target; if (!urlFields.fields.url && context.ignoreFallbackLocale) { return cms.Callback.empty(); } return cms.Callback.ofUrl(urlFields.fields.url || ''); } case ContentType.PAYLOAD: { const payloadFields = target; return cms.Callback.ofPayload(payloadFields.fields.payload); } } if (isOfType(model, TopContentType)) { return new cms.ContentCallback(model, target.sys.id); } throw new Error('Unexpected type: ' + model); } catch (e) { throw new CmsException(`Error delivering button with id '${target.sys.id}'`, e); } } //# sourceMappingURL=callback-delivery.js.map