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 environment option to Contentful connection #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
addDataTo: locals,
accessToken: 'xxx',
spaceId: 'xxx',
environment: 'xxx',
contentTypes: [
{
name: 'posts',
Expand Down Expand Up @@ -236,6 +237,22 @@ new Contentful({
})
```

### Multiple Environments

Using [Contentful's Environments](https://www.contentful.com/developers/docs/concepts/multiple-environments), you can specify different branches in a single space for staging and other environments:

```js
new Contentful({
addDataTo: locals,
accessToken: 'xxx',
preview: false;
spaceId: 'xxx',
environment: 'staging' // Or whatever your environment is called
})
```

By default `environment` is set to `master`, which is provided with every Contentful space. For each environment you want to use, specify the name as it's provided in Contentful.

### JSON Output

Finally, if you'd like to have the output written locally to a JSON file so that it's cached locally, you can pass the name of the file, resolved relative to your project's output, as a `json` option to the plugin. For example:
Expand Down
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Contentful {
this.client = contentful.createClient({
accessToken: this.accessToken,
space: this.spaceId,
host: this.preview ? 'preview.contentful.com' : ''
host: this.preview ? 'preview.contentful.com' : '',
environment: this.environment || 'master'
})
bindAllClass(this, ['apply', 'run'])
}
Expand Down