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

45 lines (39 loc) 1.25 kB
import * as contentful from 'contentful' import * as cms from '../../cms' import { ContentType } from '../../cms' import { DeliveryApi } from '../delivery-api' import { addCustomFields, CommonEntryFields } from '../delivery-utils' import { DeliveryWithReference } from './reference' export class DocumentDelivery extends DeliveryWithReference { constructor(delivery: DeliveryApi, resumeErrors: boolean) { super(ContentType.DOCUMENT, delivery, resumeErrors) } async document(id: string, context: cms.Context): Promise<cms.Document> { const entry: contentful.Entry<DocumentFields> = await this.getEntry( id, context ) return this.fromEntry(entry, context) } async fromEntry( entry: contentful.Entry<DocumentFields>, context: cms.Context ): Promise<cms.Document> { const referenceDelivery = { delivery: this.reference!, context, } return addCustomFields( new cms.Document( await this.getReference().commonFields(entry, context), this.urlFromAssetRequired(entry.fields.document) ), entry.fields, referenceDelivery, ['document'] ) } } export interface DocumentFields extends CommonEntryFields { document: contentful.Asset }