Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/autolist/contentful
https://github.com/autolist/contentful
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/autolist/contentful
- Owner: autolist
- Created: 2018-08-24T20:03:33.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T14:32:35.000Z (almost 2 years ago)
- Last Synced: 2024-10-01T14:54:15.656Z (about 1 month ago)
- Language: JavaScript
- Size: 1.41 MB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Owner: Web team
# Contentful Client
[![Test Coverage](https://api.codeclimate.com/v1/badges/232853287f54be2172aa/test_coverage)](https://codeclimate.com/repos/5b806b29d9fa0f16a200a9c4/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/232853287f54be2172aa/maintainability)](https://codeclimate.com/repos/5b806b29d9fa0f16a200a9c4/maintainability)## Installation
Using npm:
```shell
$ npm i --save @autolist/contentful
```Using yarn:
```shell
$ yarn add @autolist/contentful
```## Usage:
```
import { Item, Params } from '@autolist/contentful`
import { createClient } from 'contentful'class Article extends Item {
}// You must register all classes with the parent class if you
// want to override behavior for specific content types,
// so that we can look them up later for association parsing.
// Otherwise, the default Item class will be used.
Item.classes['article'] = Articleclass ArticleParams extends Params {
static fields = ['slug']
}const params = new ArticleParams({
// Fields will be inferred and translated to contentful params
slug: 'our-slug',
// Skip is inferred from a combination of page and limit
page: 2,
limit: 10,
// 'en' locale is assumed to be shorthand for 'en-US'
locale: 'en',
// Relationship queries are too variable to reliably
// infer, so pass them in by hand
'fields.parentPage.sys.contentType.sys.id': 'page',
'fields.parentPage.fields.slug': 'news-and-analysis'
}, Article)const client = createClient(myCredentials)
const contentfulResponse = await client.getEntries(paramsObject.toJSON())
const [article] = Article.load(contentfulResponse)
console.log(article.toJSON())
```## :hammer_and_wrench: Development
Install dependencies:
```sh
yarn
```## :robot: Testing
#### yarn:
```sh
yarn test
```## Building
#### yarn:
```sh
yarn build
```## Releasing
1. Bump version in `package.json`
1. `npm publish` (Use npm and 2FA to publish until https://github.com/yarnpkg/yarn/issues/4904 is resolved)