Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "sourcing from Contentful" section. #8861

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions docs/docs/sourcing-from-contentful.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,58 @@
title: Sourcing from Contentful
---

This is a stub. Help our community expand it.
## What is Contentful? Why choose it?

Please use the [Gatsby Style Guide](/docs/gatsby-style-guide/) to ensure your
pull request gets accepted.
Contentful is a headless Content Management System (CMS) that lets you organize your content into what could be called “modules,” or little bits of data that can be rearranged to appear nicely on mobile devices, tablets, computers, virtual reality devices (maybe someday?) and more.

Actually, the way Contentful handles bits of content means that you can push content out when new technology develops without having to redesign, rewrite, or rethink all of it for a new format.


## Prerequisites

This guide assumes that you have a Gatsby project set up. If you need to set up a project, head to the [Quick Start guide](/docs), then come back.

## Pulling data in and pushing data out

If you have a JSON file with content in it, you could pull it into Contentful using [contentful-import](https://github.com/contentful/contentful-import). If you are creating new content, you don't need this and just create content straight in Contentful.

If you do create content directly in Contentful, make sure to name your fields in a way you can remember when you create GraphQL queries. If you use GraphiQL, it can suggest fields to you, but this will only help if the field names are clear and memorable.

As far as pushing data out to your site goes, we suggest to you to use this fantastic plugin [gatsby-source-contentful](https://www.npmjs.com/package/gatsby-source-contentful), to use it, you'd need to have the `spaceId` and the `accessToken` from contentful.

## Install

```bash
npm install --save gatsby-source-contentful
```

## How to use

### With the Delivery API
```javascript
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `your_space_id_grab_it_from_contentful`,
accessToken: `your_token_id_grab_it_from_contentful`
},
},
]
```

### With the Preview API
```javascript
// In your gatsby-config.js
plugins: [
{
resolve: `gatsby-source-contentful`,
options: {
spaceId: `your_space_id_grab_it_from_contentful`,
accessToken: `your_token_id_grab_it_from_contentful`,
host: `preview.contentful.com`
},
},
]
```