@content-island/gatsby-source-plugin 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @content-island/gatsby-source-plugin
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @content-island/gatsby-source-plugin
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
// In your gatsby-config.js
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
plugins: [
|
|
16
|
+
{
|
|
17
|
+
resolve: '@content-island/gatsby-source-plugin',
|
|
18
|
+
options: {
|
|
19
|
+
accessToken: process.env.CONTENT_ISLAND_ACCESS_TOKEN,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Using with different environments
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
// In your gatsby-config.js
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
plugins: [
|
|
33
|
+
{
|
|
34
|
+
resolve: '@content-island/gatsby-source-plugin',
|
|
35
|
+
options: {
|
|
36
|
+
accessToken: process.env.CONTENT_ISLAND_ACCESS_TOKEN,
|
|
37
|
+
domain: process.env.CONTENT_ISLAND_DOMAIN, // Default: api.contentisland.net
|
|
38
|
+
apiVersion: process.env.CONTENT_ISLAND_API_VERSION, // Default: 1.0
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Using with images transformer plugin
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// In your gatsby-config.js
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
plugins: [
|
|
52
|
+
{
|
|
53
|
+
resolve: '@content-island/gatsby-source-plugin',
|
|
54
|
+
options: {
|
|
55
|
+
accessToken: process.env.CONTENT_ISLAND_ACCESS_TOKEN,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
'gatsby-plugin-sharp',
|
|
59
|
+
'gatsby-transformer-sharp',
|
|
60
|
+
'gatsby-plugin-image',
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Using with markdown transformer plugin
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// In your gatsby-config.js
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
plugins: [
|
|
72
|
+
{
|
|
73
|
+
resolve: '@content-island/gatsby-source-plugin',
|
|
74
|
+
options: {
|
|
75
|
+
accessToken: process.env.CONTENT_ISLAND_ACCESS_TOKEN,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
'gatsby-transformer-remark',
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
> NOTE: You can combine images and markdown transformer together.
|
|
@@ -16,7 +16,7 @@ let CONTENT_TYPES = [];
|
|
|
16
16
|
// Fetch all content types from Content Island
|
|
17
17
|
const getContentTypes = (client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
18
|
if (CONTENT_TYPES.length === 0) {
|
|
19
|
-
const project = yield client.
|
|
19
|
+
const project = yield client.getProject();
|
|
20
20
|
CONTENT_TYPES = project.entities;
|
|
21
21
|
}
|
|
22
22
|
return CONTENT_TYPES;
|
|
@@ -24,10 +24,10 @@ const getContentTypes = (client) => __awaiter(void 0, void 0, void 0, function*
|
|
|
24
24
|
let CONTENT_LIST = [];
|
|
25
25
|
const getContentList = (pluginOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
26
|
if (CONTENT_LIST.length === 0) {
|
|
27
|
-
const client = (0, api_client_1.
|
|
27
|
+
const client = (0, api_client_1.createClient)(pluginOptions);
|
|
28
28
|
const contentTypes = yield getContentTypes(client);
|
|
29
29
|
for (const contentType of contentTypes) {
|
|
30
|
-
const contents = yield client.
|
|
30
|
+
const contents = yield client.getContentList({ contentType: contentType.name });
|
|
31
31
|
CONTENT_LIST = [...CONTENT_LIST, ...(0, mappers_1.mapContentListFromApiToVm)(contents)];
|
|
32
32
|
}
|
|
33
33
|
}
|
package/dist/mappers.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mapContentListFromApiToVm = void 0;
|
|
4
|
+
const apiModel = require("@content-island/api-client");
|
|
4
5
|
const constants_1 = require("./constants");
|
|
5
|
-
const mapFieldFromApiToVm = (fields) => {
|
|
6
|
-
return fields.reduce((result, field) => (Object.assign(Object.assign({}, result), { [field.name]: field.value })), {});
|
|
7
|
-
};
|
|
8
|
-
const mapFieldListFromApiToVm = (fields) => Array.isArray(fields) ? mapFieldFromApiToVm(fields) : {};
|
|
9
6
|
const mapToMediaField = (field, gatsbyNodeType) => {
|
|
10
7
|
return field.isArray
|
|
11
8
|
? {
|
|
@@ -29,7 +26,7 @@ const mapContentFromApiToVm = (content, isLocalized, language) => {
|
|
|
29
26
|
const fields = isLocalized ? content.fields.filter(field => field.language === language) : content.fields;
|
|
30
27
|
return {
|
|
31
28
|
gatsbyNodeType,
|
|
32
|
-
gatsbyNode: Object.assign({ _id: content.id, _isContentIslandNode: true, _mediaFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'media'), _markdownFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'long-text'), _lastUpdate: content.lastUpdate, _isLocalized: isLocalized, _language: language },
|
|
29
|
+
gatsbyNode: Object.assign({ _id: content.id, _isContentIslandNode: true, _mediaFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'media'), _markdownFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'long-text'), _lastUpdate: content.lastUpdate, _isLocalized: isLocalized, _language: language }, apiModel.mapFieldListToModel(fields)),
|
|
33
30
|
};
|
|
34
31
|
};
|
|
35
32
|
const mapLocalizedContentFromApiToVm = (content) => {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { PluginOptions as GatsbyDefaultPluginOptions, IPluginRefOptions } from 'gatsby';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
baseUrl?: string;
|
|
5
|
-
}
|
|
2
|
+
import { Options } from '@content-island/api-client';
|
|
3
|
+
type PluginOptionsKeys = Options;
|
|
6
4
|
/**
|
|
7
5
|
* Gatsby expects the plugin options to be of type "PluginOptions" for gatsby-node APIs (e.g. sourceNodes)
|
|
8
6
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-island/gatsby-source-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Content Island - B2B Gatsby Source Plugin",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Lemoncode",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "tsc"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@content-island/api-client": "^0.
|
|
30
|
+
"@content-island/api-client": "^0.3.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"gatsby": "^5.12.4",
|