Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mayognaise/pretty-contentful
Convert Contentful data simpler
https://github.com/mayognaise/pretty-contentful
contentful prettify pretty
Last synced: 20 days ago
JSON representation
Convert Contentful data simpler
- Host: GitHub
- URL: https://github.com/mayognaise/pretty-contentful
- Owner: mayognaise
- Created: 2018-10-06T17:48:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T16:26:29.000Z (over 6 years ago)
- Last Synced: 2024-12-17T04:30:20.543Z (about 2 months ago)
- Topics: contentful, prettify, pretty
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# pretty-contentful
Convert Contentful data simpler
## Install
```bash
npm install pretty-contentful
```## Usage
```javascript
const contentful = require('contentful');
const prettify = require('pretty-contentful');const client = contentful.createClient({
accessToken: ACCESS_TOKEN,
space: SPACE
});client.getEntries({
content_type: 'page',
include: 3,
}).then(entries => prettify(entries.items));
```## Example
### `getEntry`
```javascript
const prettify = require('pretty-contentful');client.getEntry('XNZt3G2nySkKcasU2ma0k').then(entry => prettify(entry));
```After:
```json
{
"id": "XNZt3G2nySkKcasU2ma0k",
"createdAt": "2018-10-06T18:15:44.698Z",
"updatedAt": "2018-10-06T18:15:44.698Z",
"locale": "en-US",
"spaceId": "57ms2witonnw",
"contentType": "page",
"entryTitle": "About",
"slug": "/about",
"title": "About: pretty-contentful"
}
```Before:
```json
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "57ms2witonnw"
}
},
"id": "XNZt3G2nySkKcasU2ma0k",
"type": "Entry",
"createdAt": "2018-10-06T18:15:44.698Z",
"updatedAt": "2018-10-06T18:15:44.698Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 1,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "page"
}
},
"locale": "en-US"
},
"fields": {
"entryTitle": "About",
"slug": "/about",
"title": "About: pretty-contentful"
}
}
```### `getEntries`
```javascript
const prettify = require('pretty-contentful');client.getEntries({
content_type: 'page',
include: 3,
}).then(entries => prettify(entries.items));
```After:
```json
[
{
"id": "37XQFMMcfeWuCM2Oq0kkAw",
"createdAt": "2018-10-06T18:14:53.050Z",
"updatedAt": "2018-10-06T18:14:53.050Z",
"locale": "en-US",
"spaceId": "57ms2witonnw",
"contentType": "page",
"entryTitle": "Home (Default)",
"slug": "/",
"title": "Pretty Contentful",
"description": "I love Contentful!",
"image": {
"id": "5a25O6egjKKYASQ4gm0Cku",
"createdAt": "2018-10-06T18:14:40.361Z",
"updatedAt": "2018-10-06T18:14:40.361Z",
"locale": "en-US",
"spaceId": "57ms2witonnw",
"title": "og-contentful",
"file": {
"url": "//images.ctfassets.net/57ms2witonnw/5a25O6egjKKYASQ4gm0Cku/a7405e9d26fd986ba4a0b505864d6db8/og-contentful.png",
"details": {
"size": 15860,
"image": {
"width": 1200,
"height": 630
}
},
"fileName": "og-contentful.png",
"contentType": "image/png"
}
}
},
{
"id": "XNZt3G2nySkKcasU2ma0k",
"createdAt": "2018-10-06T18:15:44.698Z",
"updatedAt": "2018-10-06T18:15:44.698Z",
"locale": "en-US",
"spaceId": "57ms2witonnw",
"contentType": "page",
"entryTitle": "About",
"slug": "/about",
"title": "About: pretty-contentful"
}
]
```Before:
```json
[
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "57ms2witonnw"
}
},
"id": "37XQFMMcfeWuCM2Oq0kkAw",
"type": "Entry",
"createdAt": "2018-10-06T18:14:53.050Z",
"updatedAt": "2018-10-06T18:14:53.050Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 1,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "page"
}
},
"locale": "en-US"
},
"fields": {
"entryTitle": "Home (Default)",
"slug": "/",
"title": "Pretty Contentful",
"description": "I love Contentful!",
"image": {
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "57ms2witonnw"
}
},
"id": "5a25O6egjKKYASQ4gm0Cku",
"type": "Asset",
"createdAt": "2018-10-06T18:14:40.361Z",
"updatedAt": "2018-10-06T18:14:40.361Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 1,
"locale": "en-US"
},
"fields": {
"title": "og-contentful",
"file": {
"url": "//images.ctfassets.net/57ms2witonnw/5a25O6egjKKYASQ4gm0Cku/a7405e9d26fd986ba4a0b505864d6db8/og-contentful.png",
"details": {
"size": 15860,
"image": {
"width": 1200,
"height": 630
}
},
"fileName": "og-contentful.png",
"contentType": "image/png"
}
}
}
}
},
{
"sys": {
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "57ms2witonnw"
}
},
"id": "XNZt3G2nySkKcasU2ma0k",
"type": "Entry",
"createdAt": "2018-10-06T18:15:44.698Z",
"updatedAt": "2018-10-06T18:15:44.698Z",
"environment": {
"sys": {
"id": "master",
"type": "Link",
"linkType": "Environment"
}
},
"revision": 1,
"contentType": {
"sys": {
"type": "Link",
"linkType": "ContentType",
"id": "page"
}
},
"locale": "en-US"
},
"fields": {
"entryTitle": "About",
"slug": "/about",
"title": "About: pretty-contentful"
}
}
]
```