From a11ad3eddfb9da3c0120676f9b05bb500b693525 Mon Sep 17 00:00:00 2001 From: Kyle Simmonds <6350880+cinnamonkale@users.noreply.github.com> Date: Tue, 17 Sep 2019 10:05:01 -0500 Subject: [PATCH 1/2] Add `environment` option to Contentful connection --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 418ca2e..e7c72d3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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']) } From 3345c302c01762f9378e9c8144bb42d5cbf904f1 Mon Sep 17 00:00:00 2001 From: Kyle Simmonds <6350880+cinnamonkale@users.noreply.github.com> Date: Tue, 17 Sep 2019 10:14:43 -0500 Subject: [PATCH 2/2] Update README.md --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index edfc99a..d7ce59b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ module.exports = { addDataTo: locals, accessToken: 'xxx', spaceId: 'xxx', + environment: 'xxx', contentTypes: [ { name: 'posts', @@ -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: