@content-island/gatsby-source-plugin 0.4.0 → 0.4.1
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/dist/index.d.ts +11 -1
- package/dist/index.js +156 -8
- package/gatsby-node.js +1 -1
- package/package.json +10 -8
- package/dist/constants.d.ts +0 -14
- package/dist/constants.js +0 -22
- package/dist/gatsby-lifecycle.d.ts +0 -5
- package/dist/gatsby-lifecycle.js +0 -59
- package/dist/helpers/content-island.helpers.d.ts +0 -3
- package/dist/helpers/content-island.helpers.js +0 -36
- package/dist/helpers/error.helpers.d.ts +0 -7
- package/dist/helpers/error.helpers.js +0 -10
- package/dist/helpers/gatsby.helpers.d.ts +0 -7
- package/dist/helpers/gatsby.helpers.js +0 -93
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +0 -19
- package/dist/mappers.d.ts +0 -3
- package/dist/mappers.js +0 -52
- package/dist/models/content.model.d.ts +0 -22
- package/dist/models/content.model.js +0 -2
- package/dist/models/index.d.ts +0 -2
- package/dist/models/index.js +0 -18
- package/dist/models/plugin-options.model.d.ts +0 -14
- package/dist/models/plugin-options.model.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { GatsbyNode } from 'gatsby';
|
|
2
|
+
|
|
3
|
+
export declare const createSchemaCustomization: GatsbyNode['createSchemaCustomization'];
|
|
4
|
+
|
|
5
|
+
export declare const onCreateNode: GatsbyNode['onCreateNode'];
|
|
6
|
+
|
|
7
|
+
export declare const onPluginInit: GatsbyNode['onPluginInit'];
|
|
8
|
+
|
|
9
|
+
export declare const sourceNodes: GatsbyNode['sourceNodes'];
|
|
10
|
+
|
|
11
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import * as C from "@content-island/api-client";
|
|
2
|
+
import { createClient as u } from "@content-island/api-client";
|
|
3
|
+
import { createRemoteFileNode as _ } from "gatsby-source-filesystem";
|
|
4
|
+
const l = {
|
|
5
|
+
INCORRECT_FIELD_CONTENT: "10000"
|
|
6
|
+
}, I = {
|
|
7
|
+
[l.INCORRECT_FIELD_CONTENT]: {
|
|
8
|
+
text: (e) => e.message,
|
|
9
|
+
level: "ERROR",
|
|
10
|
+
category: "THIRD_PARTY"
|
|
11
|
+
}
|
|
12
|
+
}, E = "ContentIsland", g = {
|
|
13
|
+
markdown: "text/markdown"
|
|
14
|
+
}, w = (e, t) => e.isArray ? {
|
|
15
|
+
name: e.name,
|
|
16
|
+
gatsbyNodeType: t,
|
|
17
|
+
values: e.value,
|
|
18
|
+
isArray: e.isArray
|
|
19
|
+
} : {
|
|
20
|
+
name: e.name,
|
|
21
|
+
gatsbyNodeType: t,
|
|
22
|
+
value: e.value,
|
|
23
|
+
isArray: e.isArray
|
|
24
|
+
}, i = (e, t, o) => Array.isArray(e) ? e.filter((n) => n.type === o).map((n) => w(n, t)) : [], c = (e, t, o) => {
|
|
25
|
+
const n = `${E}${e.contentType.name}`, s = t ? e.fields.filter((y) => y.language === o) : e.fields, { id: a, ...p } = C.mapContentToModel({ ...e, fields: s });
|
|
26
|
+
return {
|
|
27
|
+
gatsbyNodeType: n,
|
|
28
|
+
gatsbyNode: {
|
|
29
|
+
_id: a,
|
|
30
|
+
_isContentIslandNode: !0,
|
|
31
|
+
_mediaFields: i(s, n, "media"),
|
|
32
|
+
_markdownFields: i(s, n, "long-text"),
|
|
33
|
+
_lastUpdate: e.lastUpdate,
|
|
34
|
+
_isLocalized: t,
|
|
35
|
+
_language: o,
|
|
36
|
+
...p
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}, R = (e) => {
|
|
40
|
+
const t = [...new Set(e.fields.map((n) => n.language).filter(Boolean))], o = t.length > 0;
|
|
41
|
+
return o ? t.map((n) => c(e, o, n)) : [c(e, o)];
|
|
42
|
+
}, F = (e) => Array.isArray(e) ? e.flatMap(R) : [];
|
|
43
|
+
let d = [];
|
|
44
|
+
const $ = async (e) => (d.length === 0 && (d = (await e.getProject()).entities), d);
|
|
45
|
+
let r = [];
|
|
46
|
+
const m = async (e) => {
|
|
47
|
+
if (r.length === 0) {
|
|
48
|
+
const t = u(e), o = await $(t);
|
|
49
|
+
for (const n of o) {
|
|
50
|
+
const s = await t.getContentList({ contentType: n.name });
|
|
51
|
+
r = [...r, ...F(s)];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return r;
|
|
55
|
+
}, L = (e, t) => ({
|
|
56
|
+
id: e,
|
|
57
|
+
context: {
|
|
58
|
+
message: t
|
|
59
|
+
}
|
|
60
|
+
}), M = async (e, t) => {
|
|
61
|
+
const o = t.gatsbyNode._isLocalized ? e.createNodeId(`${t.gatsbyNodeType}-${t.gatsbyNode._language}-${t.gatsbyNode._id}`) : e.createNodeId(`${t.gatsbyNodeType}-${t.gatsbyNode._id}`), n = {
|
|
62
|
+
...t.gatsbyNode,
|
|
63
|
+
id: o,
|
|
64
|
+
internal: {
|
|
65
|
+
type: t.gatsbyNodeType,
|
|
66
|
+
contentDigest: e.createContentDigest(t)
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
e.actions.createNode(n);
|
|
70
|
+
}, N = async (e, t) => await _({
|
|
71
|
+
url: t.link,
|
|
72
|
+
parentNodeId: e.node.id,
|
|
73
|
+
createNode: e.actions.createNode,
|
|
74
|
+
createNodeId: e.createNodeId,
|
|
75
|
+
getCache: e.getCache
|
|
76
|
+
}), T = async (e, t, o) => {
|
|
77
|
+
e.actions.createNodeField({
|
|
78
|
+
node: e.node,
|
|
79
|
+
name: t.name,
|
|
80
|
+
value: o
|
|
81
|
+
});
|
|
82
|
+
}, O = async (e, t) => {
|
|
83
|
+
let o = [];
|
|
84
|
+
for (const n of t.values) {
|
|
85
|
+
const s = await N(e, n);
|
|
86
|
+
o.push(s.id);
|
|
87
|
+
}
|
|
88
|
+
o.length > 0 && T(e, t, o);
|
|
89
|
+
}, h = async (e, t) => {
|
|
90
|
+
if (t.isArray)
|
|
91
|
+
O(e, t);
|
|
92
|
+
else {
|
|
93
|
+
const o = await N(e, t.value);
|
|
94
|
+
o && T(e, t, o.id);
|
|
95
|
+
}
|
|
96
|
+
}, f = (e) => `${e.gatsbyNodeType}MarkdownRemark`, k = async (e, t) => {
|
|
97
|
+
if (t.isArray)
|
|
98
|
+
e.reporter.panic(
|
|
99
|
+
L(l.INCORRECT_FIELD_CONTENT, "Content Island does not support fields with markdown lists.")
|
|
100
|
+
);
|
|
101
|
+
else {
|
|
102
|
+
const o = {
|
|
103
|
+
id: e.createNodeId(`${e.node.id}-${t.name}`),
|
|
104
|
+
parent: e.node.id,
|
|
105
|
+
internal: {
|
|
106
|
+
type: f(t),
|
|
107
|
+
// mediaType will allow remark plugin to transform plain text into markdown node
|
|
108
|
+
mediaType: g.markdown,
|
|
109
|
+
content: t.value,
|
|
110
|
+
contentDigest: e.createContentDigest(t.value)
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
e.actions.createNode(o), e.actions.createNodeField({
|
|
114
|
+
node: e.node,
|
|
115
|
+
name: t.name,
|
|
116
|
+
value: o.id
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, P = ({ reporter: e }) => {
|
|
120
|
+
e.setErrorMap(I);
|
|
121
|
+
}, x = async (e, t) => {
|
|
122
|
+
e.reporter.info("Customizing Content Island GraphQL schema...");
|
|
123
|
+
const o = await m(t), n = o.flatMap((a) => a.gatsbyNode._mediaFields);
|
|
124
|
+
for (const a of n)
|
|
125
|
+
e.actions.createTypes(`
|
|
126
|
+
type ${a.gatsbyNodeType} implements Node {
|
|
127
|
+
${a.name}: ${a.isArray ? "[File]" : "File"} @link(from: "fields.${a.name}")
|
|
128
|
+
}
|
|
129
|
+
`);
|
|
130
|
+
const s = o.flatMap((a) => a.gatsbyNode._markdownFields);
|
|
131
|
+
for (const a of s)
|
|
132
|
+
e.actions.createTypes(`
|
|
133
|
+
type ${a.gatsbyNodeType} implements Node {
|
|
134
|
+
${a.name}: ${f(a)} @link(from: "fields.${a.name}")
|
|
135
|
+
}
|
|
136
|
+
`);
|
|
137
|
+
}, S = async (e, t) => {
|
|
138
|
+
e.reporter.info("Creating Content Island GraphQL nodes...");
|
|
139
|
+
const o = await m(t);
|
|
140
|
+
for (const n of o)
|
|
141
|
+
await M(e, n);
|
|
142
|
+
}, z = async (e) => {
|
|
143
|
+
const t = e.node;
|
|
144
|
+
if (t._isContentIslandNode) {
|
|
145
|
+
for (const o of t._mediaFields)
|
|
146
|
+
await h(e, o);
|
|
147
|
+
for (const o of t._markdownFields)
|
|
148
|
+
await k(e, o);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
x as createSchemaCustomization,
|
|
153
|
+
z as onCreateNode,
|
|
154
|
+
P as onPluginInit,
|
|
155
|
+
S as sourceNodes
|
|
156
|
+
};
|
package/gatsby-node.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './dist/index.js';
|
package/package.json
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@content-island/gatsby-source-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Content Island - B2B Gatsby Source Plugin",
|
|
5
5
|
"private": false,
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"author": "Lemoncode",
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist",
|
|
10
11
|
"gatsby-node.js"
|
|
11
12
|
],
|
|
13
|
+
"type": "module",
|
|
12
14
|
"module": "./dist/index.js",
|
|
13
15
|
"main": "./dist/index.js",
|
|
14
16
|
"types": "./dist/index.d.ts",
|
|
15
17
|
"exports": {
|
|
16
18
|
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
17
20
|
"import": "./dist/index.js",
|
|
18
|
-
"require": "./dist/index.js"
|
|
19
|
-
"types": "./dist/index.d.ts"
|
|
21
|
+
"require": "./dist/index.js"
|
|
20
22
|
},
|
|
21
23
|
"./package.json": {
|
|
22
24
|
"import": "./package.json",
|
|
@@ -24,15 +26,15 @@
|
|
|
24
26
|
}
|
|
25
27
|
},
|
|
26
28
|
"scripts": {
|
|
27
|
-
"build": "
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"build:dev": "vite build --mode development"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@content-island/api-client": "^0.
|
|
33
|
+
"@content-island/api-client": "^0.5.0"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"gatsby": "^5.
|
|
34
|
-
"gatsby-source-filesystem": "^5.
|
|
35
|
-
"typescript": "^5.2.2"
|
|
36
|
+
"gatsby": "^5.14.1",
|
|
37
|
+
"gatsby-source-filesystem": "^5.14.0"
|
|
36
38
|
},
|
|
37
39
|
"peerDependencies": {
|
|
38
40
|
"gatsby": "^5",
|
package/dist/constants.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The IDs for your errors can be arbitrary (since they are scoped to your plugin), but it's good practice to have a system for them.
|
|
3
|
-
* For example, you could start all third-party API errors with 1000x, all transformation errors with 2000x, etc.
|
|
4
|
-
* https://www.gatsbyjs.com/docs/tutorial/creating-a-source-plugin/part-4/#task-define-custom-errors
|
|
5
|
-
*/
|
|
6
|
-
export declare const ERROR_CODES: {
|
|
7
|
-
readonly INCORRECT_FIELD_CONTENT: "10000";
|
|
8
|
-
};
|
|
9
|
-
export type ERROR_CODE_VALUE = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
10
|
-
export declare const ERROR_MAP: Record<ERROR_CODE_VALUE, any>;
|
|
11
|
-
export declare const NODE_TYPE_PREFIX = "ContentIsland";
|
|
12
|
-
export declare const MEDIA_TYPES: {
|
|
13
|
-
markdown: string;
|
|
14
|
-
};
|
package/dist/constants.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MEDIA_TYPES = exports.NODE_TYPE_PREFIX = exports.ERROR_MAP = exports.ERROR_CODES = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The IDs for your errors can be arbitrary (since they are scoped to your plugin), but it's good practice to have a system for them.
|
|
6
|
-
* For example, you could start all third-party API errors with 1000x, all transformation errors with 2000x, etc.
|
|
7
|
-
* https://www.gatsbyjs.com/docs/tutorial/creating-a-source-plugin/part-4/#task-define-custom-errors
|
|
8
|
-
*/
|
|
9
|
-
exports.ERROR_CODES = {
|
|
10
|
-
INCORRECT_FIELD_CONTENT: '10000',
|
|
11
|
-
};
|
|
12
|
-
exports.ERROR_MAP = {
|
|
13
|
-
[exports.ERROR_CODES.INCORRECT_FIELD_CONTENT]: {
|
|
14
|
-
text: context => context.message,
|
|
15
|
-
level: 'ERROR',
|
|
16
|
-
category: 'THIRD_PARTY',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
exports.NODE_TYPE_PREFIX = 'ContentIsland';
|
|
20
|
-
exports.MEDIA_TYPES = {
|
|
21
|
-
markdown: 'text/markdown',
|
|
22
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { GatsbyNode } from 'gatsby';
|
|
2
|
-
export declare const onPluginInit: GatsbyNode['onPluginInit'];
|
|
3
|
-
export declare const createSchemaCustomization: GatsbyNode['createSchemaCustomization'];
|
|
4
|
-
export declare const sourceNodes: GatsbyNode['sourceNodes'];
|
|
5
|
-
export declare const onCreateNode: GatsbyNode['onCreateNode'];
|
package/dist/gatsby-lifecycle.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.onCreateNode = exports.sourceNodes = exports.createSchemaCustomization = exports.onPluginInit = void 0;
|
|
13
|
-
const constants_1 = require("./constants");
|
|
14
|
-
const helpers_1 = require("./helpers");
|
|
15
|
-
const onPluginInit = ({ reporter }) => {
|
|
16
|
-
reporter.setErrorMap(constants_1.ERROR_MAP);
|
|
17
|
-
};
|
|
18
|
-
exports.onPluginInit = onPluginInit;
|
|
19
|
-
const createSchemaCustomization = (gatsbyApi, pluginOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
gatsbyApi.reporter.info(`Customizing Content Island GraphQL schema...`);
|
|
21
|
-
const contentList = yield (0, helpers_1.getContentList)(pluginOptions);
|
|
22
|
-
const mediaFieldList = contentList.flatMap(content => content.gatsbyNode._mediaFields);
|
|
23
|
-
for (const mediaField of mediaFieldList) {
|
|
24
|
-
gatsbyApi.actions.createTypes(`
|
|
25
|
-
type ${mediaField.gatsbyNodeType} implements Node {
|
|
26
|
-
${mediaField.name}: ${mediaField.isArray ? '[File]' : 'File'} @link(from: "fields.${mediaField.name}")
|
|
27
|
-
}
|
|
28
|
-
`);
|
|
29
|
-
}
|
|
30
|
-
const markdownFieldList = contentList.flatMap(content => content.gatsbyNode._markdownFields);
|
|
31
|
-
for (const markdownField of markdownFieldList) {
|
|
32
|
-
gatsbyApi.actions.createTypes(`
|
|
33
|
-
type ${markdownField.gatsbyNodeType} implements Node {
|
|
34
|
-
${markdownField.name}: ${(0, helpers_1.buildMarkdownNodeType)(markdownField)} @link(from: "fields.${markdownField.name}")
|
|
35
|
-
}
|
|
36
|
-
`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
exports.createSchemaCustomization = createSchemaCustomization;
|
|
40
|
-
const sourceNodes = (gatsbyApi, pluginOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
gatsbyApi.reporter.info(`Creating Content Island GraphQL nodes...`);
|
|
42
|
-
const contentList = yield (0, helpers_1.getContentList)(pluginOptions);
|
|
43
|
-
for (const content of contentList) {
|
|
44
|
-
yield (0, helpers_1.contentNodeBuilder)(gatsbyApi, content);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
exports.sourceNodes = sourceNodes;
|
|
48
|
-
const onCreateNode = (gatsbyApi) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
-
const node = gatsbyApi.node;
|
|
50
|
-
if (node._isContentIslandNode) {
|
|
51
|
-
for (const mediaField of node._mediaFields) {
|
|
52
|
-
yield (0, helpers_1.mediaNodeBuilder)(gatsbyApi, mediaField);
|
|
53
|
-
}
|
|
54
|
-
for (const markdownField of node._markdownFields) {
|
|
55
|
-
yield (0, helpers_1.markdownNodeBuilder)(gatsbyApi, markdownField);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
exports.onCreateNode = onCreateNode;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getContentList = void 0;
|
|
13
|
-
const api_client_1 = require("@content-island/api-client");
|
|
14
|
-
const mappers_1 = require("../mappers");
|
|
15
|
-
let CONTENT_TYPES = [];
|
|
16
|
-
// Fetch all content types from Content Island
|
|
17
|
-
const getContentTypes = (client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
if (CONTENT_TYPES.length === 0) {
|
|
19
|
-
const project = yield client.getProject();
|
|
20
|
-
CONTENT_TYPES = project.entities;
|
|
21
|
-
}
|
|
22
|
-
return CONTENT_TYPES;
|
|
23
|
-
});
|
|
24
|
-
let CONTENT_LIST = [];
|
|
25
|
-
const getContentList = (pluginOptions) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
if (CONTENT_LIST.length === 0) {
|
|
27
|
-
const client = (0, api_client_1.createClient)(pluginOptions);
|
|
28
|
-
const contentTypes = yield getContentTypes(client);
|
|
29
|
-
for (const contentType of contentTypes) {
|
|
30
|
-
const contents = yield client.getContentList({ contentType: contentType.name });
|
|
31
|
-
CONTENT_LIST = [...CONTENT_LIST, ...(0, mappers_1.mapContentListFromApiToVm)(contents)];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return CONTENT_LIST;
|
|
35
|
-
});
|
|
36
|
-
exports.getContentList = getContentList;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CreateNodeArgs, SourceNodesArgs } from 'gatsby';
|
|
2
|
-
import { Resource } from '@content-island/api-client';
|
|
3
|
-
import { Content, PreprocessedField } from '../models';
|
|
4
|
-
export declare const contentNodeBuilder: (gatsbyApi: SourceNodesArgs, content: Content) => Promise<void>;
|
|
5
|
-
export declare const mediaNodeBuilder: (gatsbyApi: CreateNodeArgs, mediaField: PreprocessedField<Resource>) => Promise<void>;
|
|
6
|
-
export declare const buildMarkdownNodeType: (markdownField: PreprocessedField<string>) => string;
|
|
7
|
-
export declare const markdownNodeBuilder: (gatsbyApi: CreateNodeArgs, markdownField: PreprocessedField<string>) => Promise<void>;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.markdownNodeBuilder = exports.buildMarkdownNodeType = exports.mediaNodeBuilder = exports.contentNodeBuilder = void 0;
|
|
13
|
-
const gatsby_source_filesystem_1 = require("gatsby-source-filesystem");
|
|
14
|
-
const constants_1 = require("../constants");
|
|
15
|
-
const error_helpers_1 = require("./error.helpers");
|
|
16
|
-
const contentNodeBuilder = (gatsbyApi, content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const id = content.gatsbyNode._isLocalized
|
|
18
|
-
? gatsbyApi.createNodeId(`${content.gatsbyNodeType}-${content.gatsbyNode._language}-${content.gatsbyNode._id}`)
|
|
19
|
-
: gatsbyApi.createNodeId(`${content.gatsbyNodeType}-${content.gatsbyNode._id}`);
|
|
20
|
-
const node = Object.assign(Object.assign({}, content.gatsbyNode), { id, internal: {
|
|
21
|
-
type: content.gatsbyNodeType,
|
|
22
|
-
contentDigest: gatsbyApi.createContentDigest(content),
|
|
23
|
-
} });
|
|
24
|
-
gatsbyApi.actions.createNode(node);
|
|
25
|
-
});
|
|
26
|
-
exports.contentNodeBuilder = contentNodeBuilder;
|
|
27
|
-
const getMediaFile = (gatsbyApi, resource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
return yield (0, gatsby_source_filesystem_1.createRemoteFileNode)({
|
|
29
|
-
url: resource.link,
|
|
30
|
-
parentNodeId: gatsbyApi.node.id,
|
|
31
|
-
createNode: gatsbyApi.actions.createNode,
|
|
32
|
-
createNodeId: gatsbyApi.createNodeId,
|
|
33
|
-
getCache: gatsbyApi.getCache,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
const createMediaNode = (gatsbyApi, mediaField, value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
gatsbyApi.actions.createNodeField({
|
|
38
|
-
node: gatsbyApi.node,
|
|
39
|
-
name: mediaField.name,
|
|
40
|
-
value,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
const createMediaNodeList = (gatsbyApi, mediaField) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
let fileIds = [];
|
|
45
|
-
for (const resource of mediaField.values) {
|
|
46
|
-
const file = yield getMediaFile(gatsbyApi, resource);
|
|
47
|
-
fileIds.push(file.id);
|
|
48
|
-
}
|
|
49
|
-
if (fileIds.length > 0) {
|
|
50
|
-
createMediaNode(gatsbyApi, mediaField, fileIds);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
// Preprocessing External Images in Gatsby: https://www.gatsbyjs.com/docs/how-to/images-and-media/preprocessing-external-images
|
|
54
|
-
const mediaNodeBuilder = (gatsbyApi, mediaField) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
if (mediaField.isArray) {
|
|
56
|
-
createMediaNodeList(gatsbyApi, mediaField);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
const file = yield getMediaFile(gatsbyApi, mediaField.value);
|
|
60
|
-
if (file) {
|
|
61
|
-
createMediaNode(gatsbyApi, mediaField, file.id);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
exports.mediaNodeBuilder = mediaNodeBuilder;
|
|
66
|
-
const buildMarkdownNodeType = (markdownField) => `${markdownField.gatsbyNodeType}MarkdownRemark`;
|
|
67
|
-
exports.buildMarkdownNodeType = buildMarkdownNodeType;
|
|
68
|
-
// Preprocessing Markdown in Gatsby: https://github.com/gatsbyjs/gatsby/issues/8480
|
|
69
|
-
const markdownNodeBuilder = (gatsbyApi, markdownField) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
if (markdownField.isArray) {
|
|
71
|
-
gatsbyApi.reporter.panic((0, error_helpers_1.createError)(constants_1.ERROR_CODES.INCORRECT_FIELD_CONTENT, 'Content Island does not support fields with markdown lists.'));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const textNode = {
|
|
75
|
-
id: gatsbyApi.createNodeId(`${gatsbyApi.node.id}-${markdownField.name}`),
|
|
76
|
-
parent: gatsbyApi.node.id,
|
|
77
|
-
internal: {
|
|
78
|
-
type: (0, exports.buildMarkdownNodeType)(markdownField),
|
|
79
|
-
// mediaType will allow remark plugin to transform plain text into markdown node
|
|
80
|
-
mediaType: constants_1.MEDIA_TYPES.markdown,
|
|
81
|
-
content: markdownField.value,
|
|
82
|
-
contentDigest: gatsbyApi.createContentDigest(markdownField.value),
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
gatsbyApi.actions.createNode(textNode);
|
|
86
|
-
gatsbyApi.actions.createNodeField({
|
|
87
|
-
node: gatsbyApi.node,
|
|
88
|
-
name: markdownField.name,
|
|
89
|
-
value: textNode.id,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
exports.markdownNodeBuilder = markdownNodeBuilder;
|
package/dist/helpers/index.d.ts
DELETED
package/dist/helpers/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./content-island.helpers"), exports);
|
|
18
|
-
__exportStar(require("./error.helpers"), exports);
|
|
19
|
-
__exportStar(require("./gatsby.helpers"), exports);
|
package/dist/mappers.d.ts
DELETED
package/dist/mappers.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.mapContentListFromApiToVm = void 0;
|
|
15
|
-
const apiModel = require("@content-island/api-client");
|
|
16
|
-
const constants_1 = require("./constants");
|
|
17
|
-
const mapToMediaField = (field, gatsbyNodeType) => {
|
|
18
|
-
return field.isArray
|
|
19
|
-
? {
|
|
20
|
-
name: field.name,
|
|
21
|
-
gatsbyNodeType,
|
|
22
|
-
values: field.value,
|
|
23
|
-
isArray: field.isArray,
|
|
24
|
-
}
|
|
25
|
-
: {
|
|
26
|
-
name: field.name,
|
|
27
|
-
gatsbyNodeType,
|
|
28
|
-
value: field.value,
|
|
29
|
-
isArray: field.isArray,
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
const mapToPreprocessedFieldList = (fields, gatsbyNodeType, fieldType) => Array.isArray(fields)
|
|
33
|
-
? fields.filter(field => field.type === fieldType).map(field => mapToMediaField(field, gatsbyNodeType))
|
|
34
|
-
: [];
|
|
35
|
-
const mapContentFromApiToVm = (content, isLocalized, language) => {
|
|
36
|
-
const gatsbyNodeType = `${constants_1.NODE_TYPE_PREFIX}${content.contentType.name}`;
|
|
37
|
-
const fields = isLocalized ? content.fields.filter(field => field.language === language) : content.fields;
|
|
38
|
-
const _a = apiModel.mapContentToModel(Object.assign(Object.assign({}, content), { fields })), { id } = _a, model = __rest(_a, ["id"]);
|
|
39
|
-
return {
|
|
40
|
-
gatsbyNodeType,
|
|
41
|
-
gatsbyNode: Object.assign({ _id: id, _isContentIslandNode: true, _mediaFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'media'), _markdownFields: mapToPreprocessedFieldList(fields, gatsbyNodeType, 'long-text'), _lastUpdate: content.lastUpdate, _isLocalized: isLocalized, _language: language }, model),
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const mapLocalizedContentFromApiToVm = (content) => {
|
|
45
|
-
const languages = [...new Set(content.fields.map(field => field.language).filter(Boolean))];
|
|
46
|
-
const isLocalized = languages.length > 0;
|
|
47
|
-
return isLocalized
|
|
48
|
-
? languages.map(language => mapContentFromApiToVm(content, isLocalized, language))
|
|
49
|
-
: [mapContentFromApiToVm(content, isLocalized)];
|
|
50
|
-
};
|
|
51
|
-
const mapContentListFromApiToVm = (contentList) => Array.isArray(contentList) ? contentList.flatMap(mapLocalizedContentFromApiToVm) : [];
|
|
52
|
-
exports.mapContentListFromApiToVm = mapContentListFromApiToVm;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Resource } from '@content-island/api-client';
|
|
2
|
-
export type PreprocessedField<Value> = {
|
|
3
|
-
name: string;
|
|
4
|
-
gatsbyNodeType: string;
|
|
5
|
-
value?: Value;
|
|
6
|
-
values?: Value[];
|
|
7
|
-
isArray: boolean;
|
|
8
|
-
};
|
|
9
|
-
export interface ContentIslandNode {
|
|
10
|
-
_id: string;
|
|
11
|
-
_isContentIslandNode: boolean;
|
|
12
|
-
_mediaFields: PreprocessedField<Resource>[];
|
|
13
|
-
_markdownFields: PreprocessedField<string>[];
|
|
14
|
-
_lastUpdate: Date;
|
|
15
|
-
_isLocalized: boolean;
|
|
16
|
-
_language?: string;
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
}
|
|
19
|
-
export interface Content {
|
|
20
|
-
gatsbyNodeType: string;
|
|
21
|
-
gatsbyNode: ContentIslandNode;
|
|
22
|
-
}
|
package/dist/models/index.d.ts
DELETED
package/dist/models/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./content.model"), exports);
|
|
18
|
-
__exportStar(require("./plugin-options.model"), exports);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { PluginOptions as GatsbyDefaultPluginOptions, IPluginRefOptions } from 'gatsby';
|
|
2
|
-
import { Options } from '@content-island/api-client';
|
|
3
|
-
type PluginOptionsKeys = Options;
|
|
4
|
-
/**
|
|
5
|
-
* Gatsby expects the plugin options to be of type "PluginOptions" for gatsby-node APIs (e.g. sourceNodes)
|
|
6
|
-
*/
|
|
7
|
-
export interface PluginOptionsInternal extends PluginOptionsKeys, GatsbyDefaultPluginOptions {
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* These are the public TypeScript types for consumption in gatsby-config
|
|
11
|
-
*/
|
|
12
|
-
export interface IPluginOptions extends PluginOptionsKeys, IPluginRefOptions {
|
|
13
|
-
}
|
|
14
|
-
export {};
|