Skip to content

Commit 6a742f0

Browse files
authored
Merge pull request #133 from Kentico/feature/preview-create
Feature/preview support
2 parents c96c701 + bb2919e commit 6a742f0

39 files changed

+668
-84
lines changed

.vscode/launch.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"name": "Develop site",
2929
"program": "${workspaceFolder}/node_modules/gatsby/dist/bin/gatsby",
3030
"args": [
31-
"develop"
31+
"develop",
32+
"--verbose"
3233
],
3334
"stopOnEntry": false,
3435
"cwd": "${workspaceFolder}/site",
@@ -39,11 +40,15 @@
3940
],
4041
"restart": true,
4142
"internalConsoleOptions": "neverOpen",
42-
"env": {
43+
"env": {
4344
"NODE_ENV": "development",
45+
"ENABLE_GATSBY_REFRESH_ENDPOINT": "true",
4446
// "DEBUG": "gatsby:*"
4547
},
4648
"console": "integratedTerminal",
49+
"skipFiles": [
50+
"<node_internals>/**/*.js"
51+
]
4752
}
4853
]
4954
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ To lint all of the packages as well as a development site, you could use one com
7979

8080
As a publishing framework, there is a [Lerna](https://github.com/lerna/lerna) framework set up. This package is using [Fixed/Locked mode](https://github.com/lerna/lerna#fixedlocked-mode-default). All minor and major changes should publish all packages, in case of patch version, it is up to developer decision.
8181

82-
### How to publish new (vNext) version
82+
### How to publish new (vNext) version
8383

8484
If you have the rights to publish packages, just use [`lerna publish`](https://github.com/lerna/lerna/tree/master/commands/publish#readme) with appropriate tags and then specify the version when prompted. All the changes made by lerna are automatically committed.
8585

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"!packages/site",
55
"packages/*"
66
],
7-
"version": "6.0.0-vnext.1"
7+
"version": "6.0.0-vnext.4"
88
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
"prepublishOnly": "yarn build",
2424
"build:site": "yarn workspace @kentico/gatsby-starter-kontent-hello-world build",
2525
"develop:site": "yarn workspace @kentico/gatsby-starter-kontent-hello-world develop",
26-
"develop:site:playground": "cross-env GATSBY_GRAPHQL_IDE=playground yarn develop:site",
26+
"develop:site:playground": "cross-env GATSBY_GRAPHQL_IDE=playground yarn develop:site",
2727
"watch:source": "yarn workspace @kentico/gatsby-source-kontent watch",
2828
"watch:components": "yarn workspace @kentico/gatsby-kontent-components watch",
2929
"build:source": "yarn workspace @kentico/gatsby-source-kontent build",
3030
"test:source": "yarn workspace @kentico/gatsby-source-kontent test",
3131
"set:version": "export LERNA_VERSION=\"$(node -e \"require('./lerna.json').version\")\"",
32-
"publish:vnext-alpha": "lerna publish --no-git-tag-version --force-publish --dist-tag=vnext-alpha",
33-
"publish:vnext-beta": "lerna publish --no-git-tag-version --force-publish --dist-tag=vnext-beta",
32+
"publish:vnext-alpha": "lerna publish --force-publish --tag-version-prefix='' --dist-tag=vnext-alpha",
33+
"publish:vnext-beta": "lerna publish --force-publish --tag-version-prefix='' --dist-tag=vnext-beta",
3434
"publish:vnext": "lerna publish --force-publish --tag-version-prefix='' --dist-tag=vnext"
3535
},
3636
"devDependencies": {

packages/gatsby-kontent-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@kentico/gatsby-kontent-components",
33
"description": "Source plugin providing Kentico Kontent data from REST Delivery API",
4-
"version": "6.0.0-vnext.1",
4+
"version": "6.0.0-vnext.4",
55
"main": "dist/index.js",
66
"license": "MIT",
77
"author": {

packages/gatsby-source-kontent/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ This plugin does not need to use `yarn`, if want to use it in you project, see [
4141
- `languageCodenames`\* - \<`string[]`\> array of language codenames that defines [what languages a configured for the project](https://docs.kontent.ai/tutorials/develop-apps/get-content/getting-localized-content?tech=javascript#section-project-languages) - the first one is considered as the **default one**. Initial "Getting started" project has configured just one language `default`.
4242
- `includeTaxonomies` - \<`boolean`\> include [taxonomies](#Querying-Kontent-Taxonomies) to GraphQL model. Turned off by default.
4343
- `includeTypes` - \<`boolean`\> include [types](#Querying-Kontent-Types) to GraphQL model. Turned off by default.
44-
- `authorizationKey` - \<`string`\> For preview/secured API key - depends on `usePreviewUrl` config.
44+
- `authorizationKey` - \<`string`\> For preview/secured API key - depends on `usePreviewUrl` config. Consider using [dotenv](https://www.npmjs.com/package/dotenv) package for storing keys securely in environment variables.
4545
- `usePreviewUrl` - \<`boolean`\> when `true`, "`preview-deliver.kontent.ai`" used as [primary domain for data source](https://docs.kontent.ai/reference/delivery-api#section/Production-vs.-Preview). Turned off by default.
46+
- `proxy`:
47+
- `deliveryDomain` - \<`string`\> Base url used for all requests. Defaults to `deliver.kontent.ai`.
48+
- `previewDeliveryDomain` - \<`string`\> Base url used for preview requests. Defaults to `preview-deliver.kontent.ai`.
4649
- `includeRawContent` - \<`boolean`\> allows to include `internal.content` property as a part fo the GraphQL model. Turned off by default.
4750

4851
\* required property
@@ -72,8 +75,12 @@ module.exports = {
7275
includeTaxonomies: true, // opt-out by default
7376
includeTypes: true, // opt-out by default
7477
usePreviewUrl: true, // false by default
75-
authorizationKey: '<API KEY>', // For preview/secured API key - depends on usePreviewUrl setting
78+
authorizationKey: '<API KEY>', // for preview/secured API key - depends on `usePreviewUrl` setting - consider using environment variables to store the key securely
7679
includeRawContent: true, // opt-out by default - include `internal.content` property in the gatsby nodes
80+
proxy: {
81+
deliveryDomain: 'custom.delivery.kontent.my-proxy.com',
82+
previewDeliveryDomain: "custom.preview.delivery.kontent.my-proxy.com"
83+
}
7784
},
7885
},
7986
/// ...
@@ -430,6 +437,12 @@ query Taxonomies {
430437
}
431438
```
432439

440+
## How to integrate with Gatsby Cloud
441+
442+
If you choose to maintain you Gatsby site on [Gatsby Cloud](https://gatsbyjs.com), use will need to register two webhooks from Kentico Kontent Kontent to Gatsby Cloud. Follow [the tutorial](./docs/GATSBY-CLOUD.md) for more information. All webhook notification that are not mentioned in the tutorial will be ignored by the plugin.
443+
444+
Please note that change in taxonomies or content types require manual rebuild of the site, because these structural data affects GraphQL schema.
445+
433446
## How to run tests
434447

435448
The package is using [Jest](http://jest.org/) framework for testing.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Getting started with Gatsby Cloud and Kontent
2+
3+
Learn how to connect Gatsby Cloud with Kentico Kontent based Gatsby site.
4+
5+
In this tutorial you will discover how to easily integrate site sourced by Kentico Kontent with Gatsby Cloud.
6+
7+
You will
8+
9+
* Create a website using data from Kentico Kontent.
10+
* Store its source Code on GitHub.
11+
* Register this Github repository in Gatsby Cloud.
12+
* Configure Kentico Kontent webhooks to notify Gatsby Cloud about the content changes on preview environment as well as on production.
13+
* Configure preview URLs in Kentico Kontent.
14+
15+
## What are Gatsby Cloud and Kontent, and why use them together
16+
17+
[Kontent](https://kontent.ai) is a headless CMS that content editors can use to edit and publish content. It is a Content-as-a-Service solution that gives enterprises control over their entire content lifecycle in a single unified environment. Gatsby Cloud allows you to integrate your site with Kontent in order to run performant builds and preview content changes made in the CMS before publishing.
18+
19+
## Setting up a Kontent and Gatsby site
20+
21+
First, you’ll need a Gatsby site with a [gatsby-source-kontent](https://www.gatsbyjs.org/packages/@kentico/gatsby-source-kontent) source plugin to pull data from Kontent. If you haven’t set that up yet, you can quickly create a new project by using the [gatsby-starter-kontent-lumen](https://github.com/Kentico/gatsby-starter-kontent-lumen) repository. ~~To achieve it, see the [Getting started](https://github.com/kentico/gatsby-starter-kontent-lumen#getting-started) tutorial.~~
22+
23+
> Note that source plugin version supporting Gatsby Cloud is in beta phase (internally called [`vNext`](https://github.com/Kentico/gatsby-source-kontent/tree/vNext/packages/gatsby-source-kontent#readme) version), so use the link to the development branch to [Getting started](https://github.com/Simply007/gatsby-starter-kontent-lumen/tree/vNext#getting-started) section. to be able to spin up project supporting Gatsby Cloud.
24+
25+
## Signing in to Gatsby Cloud
26+
27+
[Access Gatsby Cloud](https://gatsbyjs.com/dashboard/sites/create) and select **Sign in with GitHub**. You’ll be asked to authorize the Gatsby Cloud app with your GitHub account. If you need to request access to one or more repositories, you can click *request access* now or later when creating an instance.
28+
29+
Once signed in, configuring Gatsby Cloud with Kontent requires several steps that are walked through below.
30+
31+
### Creating an instance
32+
33+
Start by [registering you GitHub repository](https://gatsbyjs.com/dashboard/sites/create).
34+
35+
Use the **I already have a Gatsby site** flow to manually integrate your site.
36+
37+
![Add my own site](./assets/import-flow-start.png)
38+
39+
### Select an organization & repository
40+
41+
Pick your Gatsby site from the list of GitHub repositories.
42+
43+
If you don’t see your site, it might be because it belongs to a GitHub organization rather than your personal account. You can connect a new GitHub Organization.
44+
45+
*Note: Repositories must contain one Gatsby project configured at their root to be enabled. Gatsby Cloud works best with Gatsby version 2.20.36 and higher.*
46+
47+
You’ll need to select a branch and then indicate the publish directory where the `gatsby-config.js` lives. If you leave the field blank, it defaults to the root of the site.
48+
49+
![Gatsby Cloud Add an instance page](./assets/select-repo.png)
50+
51+
Once the branch and publish directory are correct, select **Next**.
52+
53+
### Create the instance
54+
55+
Click **Skip this step** to configure Kontent manually.
56+
57+
![Integration Step - automatic or manual](./assets/integration-step.png)
58+
59+
*Gatsby Cloud will automatically try and detect environment variables necessary in your `gatsby-config.js`. However — consider adding any additional variables that the automatic detection may have missed. See [Setting up Environment Variables](#setting-up-environment-variables) for more info. You'll be able to add, delete, or update these later on in your Site Settings.*
60+
61+
### Setting up Environment Variables
62+
63+
An environment variable references a value that can affect how running processes will behave in a specific environment, such as staging and production environments. You must save your environment variables in Gatsby Cloud to authorize your instance to pull source data from Kontent.
64+
65+
First, open your Kontent project and go to **Project settings** > **API Keys**.
66+
On the API keys screen, copy the values for **Project ID** and **Preview API key** (Primary or Secondary).
67+
68+
![Kontent API keys section](./assets/kontent-api-keys.png)
69+
70+
Then go to **Project settings** > **Localization** to get the codenames of your project languages.
71+
72+
![Kontent Localization configuration section](./assets/kontent-localization.png)
73+
74+
The language codenames used in the [`gatsby-starter-kontent-lumen`](https://github.com/Kentico/gatsby-starter-kontent-lumen) sample app are `en-US,cs-CZ`.
75+
76+
Value | Environment Variable Name
77+
------------ | -------------
78+
<YOUR_PROJECT_ID> | KONTENT_PROJECT_ID
79+
<YOUR_PREVIEW_API_KEY> | KONTENT_PREVIEW_KEY
80+
<YOUR_LANGUAGE1,YOUR_LANGUAGE2> | KONTENT_LANGUAGE_CODENAMES
81+
82+
You will want to set `KONTENT_PREVIEW_ENABLED` to `true` for Preview and `false` for Builds.
83+
84+
![Environment variables](./assets/environment-variables.png)
85+
86+
Once you’ve entered your variables, click **Save** and then **Create site**.
87+
88+
Go to the *Preview* tab and wait for the preview instance to be created.
89+
90+
## Webhooks: Configuring your Gatsby site to be updated with content changes
91+
92+
To connect Kontent with your Gatsby Cloud instance, you’ll need to [configure a webhook](https://docs.kontent.ai/tutorials/develop-apps/integrate/webhooks#a-creating-a-webhook) in Kontent so that content changes can be pushed to Gatsby Cloud.
93+
94+
You’ll add two webhooks in Kontent: one for Gatsby Preview and another for Gatsby Builds.
95+
96+
### Adding a Preview Webhook
97+
98+
Navigate to your Gatsby Cloud instance and click **Site Settings**. Copy the *Preview Webhook* on this page.
99+
100+
![Copying the Preview webhook URL](./assets/webhook-preview.png)
101+
102+
In your Kentico Kontent project, go to **Project settings** > **Webhooks** and click **Create new webhook**.
103+
104+
![Kontent webhooks menu](./assets/kontent-webhooks.png)
105+
106+
Name the webhook and paste the *Preview webhook* into the URL address field.
107+
108+
> Following webhook triggers are currently available via [API](https://docs.kontent.ai/reference/management-api-v2#operation/add-a-webhook) (use `preview_delivery_api_content_changes` as trigers section and `uspert` + `archive` as operations). The UI and documentation is about to be released in the next iteration. (The UI is currently available on QA environment)
109+
110+
In the webhook configuration, select the *Create or Update* and *Delete* triggers under DELIVERY PREVIEW API TRIGGERS.
111+
112+
![Kontent preview webhook configuration](./assets/preview-webhook-configuration.png)
113+
114+
Click **Save**.
115+
116+
Your Preview webhook is now ready! When you change your content in Kontent, your Gatsby Preview will update!
117+
118+
### Adding a Build Webhook
119+
120+
Navigate to your Gatsby Cloud instance and click **Site Settings**. Copy the Build Webhook on this page.
121+
122+
![Copying the Build webhook URL](./assets/webhook-builds.png)
123+
124+
In Kentico Kontent, go to **Project settings** > **Webhooks** and click **Create new webhook**.
125+
126+
![Kontent webhooks menu with one webhook](./assets/kontent-webhooks-with-webhook.png)
127+
128+
Name the webhook and paste the *Build webhook* in the URL address field.
129+
130+
In the webhook configuration, select the *Publish* and *Unpublish* triggers under DELIVERY API TRIGGERS.
131+
132+
![Kontent build webhook configuration](./assets/build-webhook-configuration.png)
133+
134+
Click **Save**.
135+
136+
Your Build webhook is now ready! When you publish/unpublish content in Kontent, your Gatsby Build will update!
137+
138+
## Setting the Gatsby Preview Domain for Kontent
139+
140+
To open the Gatsby Cloud preview right from Kentico Kontent, you need to [configure preview URLs](https://docs.kontent.ai/tutorials/develop-apps/build-strong-foundation/set-up-preview#a-set-up-content-preview-in-your-project) for your content. The following instructions assume you're using the [`gatsby-starter-kontent-lumen`](https://github.com/Kentico/gatsby-starter-kontent-lumen) sample app.
141+
142+
Navigate to your Gatsby Cloud instance and click **Preview**. Copy the preview URL.
143+
144+
![Gatsby cloud preview URL](./assets/gatsby-cloud-preview-url.png)
145+
146+
In Kentico Kontent, go to **Project settings** > **Preview URLs** and provide the URLs according to your routes configuration.
147+
148+
![Preview URLs configuration](./assets/preview-urls.png)
149+
150+
Now you can open the content preview right from Kentico Kontent UI!
151+
152+
![Preview button showcase in Kontent](./assets/preview-showcase.png)
153+
154+
## Wrapping Up
155+
156+
At this point, you have a Kontent instance configured to best support Gatsby Cloud. Edit content, click the Preview button, and watch it appear live in Gatsby Cloud!

packages/gatsby-source-kontent/docs/UPGRADE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ If you want to extend the model with `contentItems` feel free to do so using [Co
6464
All nodes had a `usedByContentItems` property that reflects the other nodes in which the given node is used as linked content in Linked items or Rich text elements.
6565
Now it is possible to substitute this property by using [Linked from relationship](../../../site/README.md#Linked-from-relationship), it is just required to specify an element to gather the links from.
6666

67+
### Different Item Node IDs
68+
69+
In previous version there was a Node ID generated from item `system.codename`, `preferred_language`, and some prefix.
70+
Since the `system.codename` is changeable for content item, now as an input for node ID generation function `system.id` is used.
71+
72+
If you are using hard-coded Node ID in your queries to get/filter specific Kontent item node(s), you need to make the adjustments - IDs will be different for version 6.
73+
6774
## From `4.x.x` to `5.x.x`
6875

6976
This upgrade is necessary to fix the [colliding identifiers](https://github.com/Kentico/gatsby-source-kontent/issues/110) issue.
50.5 KB
Loading
46.3 KB
Loading

0 commit comments

Comments
 (0)