@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
42 lines (36 loc) • 1.11 kB
text/typescript
import * as contentful from 'contentful'
import * as cms from '../../cms'
import { Context } from '../../cms'
import { DeliveryApi } from '../delivery-api'
import {
addCustomFields,
CommonEntryFields,
ContentfulEntryUtils,
} from '../delivery-utils'
import { DeliveryWithReference } from './reference'
export class UrlDelivery extends DeliveryWithReference {
constructor(delivery: DeliveryApi, resumeErrors: boolean) {
super(cms.ContentType.URL, delivery, resumeErrors)
}
async url(id: string, context: Context): Promise<cms.Url> {
const entry: contentful.Entry<UrlFields> = await this.getEntry(id, context)
return this.fromEntry(entry, context)
}
fromEntry(entry: contentful.Entry<UrlFields>, context: Context) {
const referenceDelivery = {
delivery: this.reference!,
context,
}
return addCustomFields(
new cms.Url(
ContentfulEntryUtils.commonFieldsFromEntry(entry),
entry.fields.url || ''
),
entry.fields,
referenceDelivery
)
}
}
export interface UrlFields extends CommonEntryFields {
url?: string
}