gatsby-attainlabs-cms 1.0.46 → 1.0.48
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 +2 -0
- package/dist/sliceWrapper.js +14 -5
- package/gatsby-node.js +92 -54
- package/package.json +1 -1
- package/src/sliceWrapper.tsx +12 -4
package/README.md
CHANGED
|
@@ -58,6 +58,8 @@ module.exports = {
|
|
|
58
58
|
brand: "Cash Money", // LendDirect | Cash Money | Heights Finance adding-puck-for-visual-code-editing
|
|
59
59
|
// personalAccessToken: "optional-fallback", // not recommended, but supported
|
|
60
60
|
environment: "production", // production | dev
|
|
61
|
+
fetch: ["blogs", "disclaimers", "faqs"] // Array of data to fetch from database
|
|
62
|
+
debug: false // Console logs blocks created
|
|
61
63
|
},
|
|
62
64
|
},
|
|
63
65
|
],
|
package/dist/sliceWrapper.js
CHANGED
|
@@ -12,7 +12,12 @@ export default function SliceWrapper({ sliceContext, data, }) {
|
|
|
12
12
|
console.warn(`Component "${pathFormatted}" not found in CMS_COMPONENTS`);
|
|
13
13
|
return null;
|
|
14
14
|
}
|
|
15
|
-
return (_jsx(Component, { ...props, trustPilotData: data.allTrustPilotReviews.edges[0].node,
|
|
15
|
+
return (_jsx(Component, { ...props, trustPilotData: data.allTrustPilotReviews.edges[0].node,
|
|
16
|
+
/* CHECK_DISCLAIMERS_START */
|
|
17
|
+
disclaimers: data.allDisclaimers,
|
|
18
|
+
/* CHECK_DISCLAIMERS_END */
|
|
19
|
+
/* CHECK_BLOGS_START */
|
|
20
|
+
blogs: {
|
|
16
21
|
sliderBlogs: {
|
|
17
22
|
...data.sliderBlogs,
|
|
18
23
|
},
|
|
@@ -54,15 +59,18 @@ export const TrustPilotQuery = graphql `
|
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
}
|
|
62
|
+
# CHECK_DISCLAIMERS_START
|
|
57
63
|
allDisclaimers: allAttainLabsCmsDisclaimers {
|
|
58
|
-
|
|
64
|
+
edges {
|
|
59
65
|
node {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
content
|
|
67
|
+
published
|
|
68
|
+
order
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
}
|
|
72
|
+
# CHECK_DISCLAIMERS_END
|
|
73
|
+
# CHECK_BLOGS_START
|
|
66
74
|
allBlogs: allAttainLabsCmsBlogs {
|
|
67
75
|
edges {
|
|
68
76
|
node {
|
|
@@ -126,5 +134,6 @@ export const TrustPilotQuery = graphql `
|
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
# CHECK_BLOGS_END
|
|
129
138
|
}
|
|
130
139
|
`;
|
package/gatsby-node.js
CHANGED
|
@@ -13,6 +13,8 @@ const brands = {
|
|
|
13
13
|
"Attain Finance": "attainfinance",
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const generateSliceWrapper = () => {};
|
|
17
|
+
|
|
16
18
|
const generatePage = async (blocks, layout, isNested) => {
|
|
17
19
|
// Validate input parameters
|
|
18
20
|
if (!Array.isArray(blocks)) {
|
|
@@ -62,25 +64,19 @@ const generatePage = async (blocks, layout, isNested) => {
|
|
|
62
64
|
const getAllBlogs = (data) => {
|
|
63
65
|
const allBlogs = [];
|
|
64
66
|
const getDatePublished = (entry) => {
|
|
65
|
-
const date =
|
|
66
|
-
entry?.draft?.blocks?.root?.props?.datePublished ||
|
|
67
|
-
entry?.blocks?.root?.props?.datePublished;
|
|
67
|
+
const date = entry?.blocks?.root?.props?.datePublished;
|
|
68
68
|
return date ? new Date(date).getTime() : 0;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
for (let [key, value] of Object.entries(data)) {
|
|
72
|
-
const category =
|
|
73
|
-
value?.draft?.blocks?.root?.props?.category ||
|
|
74
|
-
value?.blocks?.root?.props?.category;
|
|
72
|
+
const category = value?.blocks?.root?.props?.category;
|
|
75
73
|
if (category === "blog") {
|
|
76
74
|
value = { ...value, parentFolder: value.folderUrl };
|
|
77
75
|
allBlogs.push(value);
|
|
78
76
|
}
|
|
79
77
|
if (value.hasOwnProperty("children")) {
|
|
80
78
|
for (let [childKey, childValue] of Object.entries(value["children"])) {
|
|
81
|
-
const childCategory =
|
|
82
|
-
childValue?.draft?.blocks?.root?.props?.category ||
|
|
83
|
-
childValue?.blocks?.root?.props?.category;
|
|
79
|
+
const childCategory = childValue?.blocks?.root?.props?.category;
|
|
84
80
|
|
|
85
81
|
if (childCategory === "blog") {
|
|
86
82
|
childValue = { ...childValue, parentFolder: value.folderUrl };
|
|
@@ -101,6 +97,7 @@ exports.onPreInit = async (_, pluginOptions) => {
|
|
|
101
97
|
azureBranch,
|
|
102
98
|
personalAccessToken: patOption,
|
|
103
99
|
environment,
|
|
100
|
+
fetch: fetchConfig,
|
|
104
101
|
} = pluginOptions;
|
|
105
102
|
|
|
106
103
|
// Try env first, then plugin option fallback
|
|
@@ -183,8 +180,39 @@ exports.onPreInit = async (_, pluginOptions) => {
|
|
|
183
180
|
}
|
|
184
181
|
const fileName = path.basename(localPath);
|
|
185
182
|
const destFile = path.join(targetPath, fileName);
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
|
|
184
|
+
if (fileName === "sliceWrapper.tsx") {
|
|
185
|
+
let content = fs.readFileSync(localPath, "utf8");
|
|
186
|
+
|
|
187
|
+
if (!fetchConfig || !fetchConfig.includes("blogs")) {
|
|
188
|
+
content = content.replace(
|
|
189
|
+
/# CHECK_BLOGS_START[\s\S]*?# CHECK_BLOGS_END/g,
|
|
190
|
+
""
|
|
191
|
+
);
|
|
192
|
+
content = content.replace(
|
|
193
|
+
/\/\* CHECK_BLOGS_START \*\/[\s\S]*?\/\* CHECK_BLOGS_END \*\//g,
|
|
194
|
+
""
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (!fetchConfig || !fetchConfig.includes("disclaimers")) {
|
|
199
|
+
content = content.replace(
|
|
200
|
+
/# CHECK_DISCLAIMERS_START[\s\S]*?# CHECK_DISCLAIMERS_END/g,
|
|
201
|
+
""
|
|
202
|
+
);
|
|
203
|
+
content = content.replace(
|
|
204
|
+
/\/\* CHECK_DISCLAIMERS_START \*\/[\s\S]*?\/\* CHECK_DISCLAIMERS_END \*\//g,
|
|
205
|
+
""
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
fs.writeFileSync(localPath, content);
|
|
210
|
+
fs.writeFileSync(destFile, content);
|
|
211
|
+
console.log(`✅ Copied and transformed ${destFile}`);
|
|
212
|
+
} else {
|
|
213
|
+
fs.copyFileSync(localPath, destFile);
|
|
214
|
+
console.log(`✅ Copied ${destFile}`);
|
|
215
|
+
}
|
|
188
216
|
});
|
|
189
217
|
|
|
190
218
|
// Loop through targets
|
|
@@ -218,7 +246,8 @@ exports.onPreInit = async (_, pluginOptions) => {
|
|
|
218
246
|
(i) =>
|
|
219
247
|
!i.isFolder &&
|
|
220
248
|
i.gitObjectType === "blob" &&
|
|
221
|
-
posix.basename(i.path) !== "config.tsx"
|
|
249
|
+
posix.basename(i.path) !== "config.tsx" &&
|
|
250
|
+
posix.basename(i.path) !== "preview.tsx"
|
|
222
251
|
);
|
|
223
252
|
|
|
224
253
|
console.log(`Found ${items.length} files in ${repoPath}`);
|
|
@@ -321,7 +350,12 @@ exports.sourceNodes = async (
|
|
|
321
350
|
pluginOptions
|
|
322
351
|
) => {
|
|
323
352
|
const { createNode } = actions;
|
|
324
|
-
const {
|
|
353
|
+
const {
|
|
354
|
+
trustpilotApiKey,
|
|
355
|
+
brand,
|
|
356
|
+
environment,
|
|
357
|
+
fetch: fetchConfig,
|
|
358
|
+
} = pluginOptions;
|
|
325
359
|
const apiKey = process.env.TRUSTPILOT_API_KEY || trustpilotApiKey;
|
|
326
360
|
|
|
327
361
|
if (environment === "dev") {
|
|
@@ -410,7 +444,6 @@ exports.sourceNodes = async (
|
|
|
410
444
|
}
|
|
411
445
|
|
|
412
446
|
// Blogs node creation
|
|
413
|
-
|
|
414
447
|
const fetchData = async () => {
|
|
415
448
|
try {
|
|
416
449
|
const response = await fetch(
|
|
@@ -427,49 +460,54 @@ exports.sourceNodes = async (
|
|
|
427
460
|
}
|
|
428
461
|
};
|
|
429
462
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
463
|
+
if (fetchConfig) {
|
|
464
|
+
const firebaseData = await fetchData();
|
|
465
|
+
if (fetchConfig.includes("blogs")) {
|
|
466
|
+
const allBlogs = getAllBlogs(firebaseData.pages);
|
|
467
|
+
|
|
468
|
+
for (const blog of allBlogs) {
|
|
469
|
+
const id = createNodeId(`attain-cms-blog-${blog.id}`);
|
|
470
|
+
blog.blocks.root.props.datePublished = new Date(
|
|
471
|
+
blog.blocks.root.props.datePublished
|
|
472
|
+
);
|
|
473
|
+
const node = {
|
|
474
|
+
...blog,
|
|
475
|
+
id,
|
|
476
|
+
_id: blog.id,
|
|
477
|
+
parent: null,
|
|
478
|
+
children: [],
|
|
479
|
+
internal: {
|
|
480
|
+
type: "AttainLabsCmsBlogs",
|
|
481
|
+
contentDigest: createContentDigest(blog),
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
createNode(node);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
453
487
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
488
|
+
// Disclaimers Source Node
|
|
489
|
+
if (fetchConfig.includes("disclaimers")) {
|
|
490
|
+
const allDisclaimers = Object.values(firebaseData.disclaimers);
|
|
491
|
+
for (const disclaimer of allDisclaimers) {
|
|
492
|
+
const id = createNodeId(`attain-cms-disclaimer-${disclaimer.id}`);
|
|
493
|
+
const node = {
|
|
494
|
+
...disclaimer,
|
|
495
|
+
id,
|
|
496
|
+
_id: disclaimer.id,
|
|
497
|
+
parent: null,
|
|
498
|
+
children: [],
|
|
499
|
+
internal: {
|
|
500
|
+
type: "AttainLabsCmsDisclaimers",
|
|
501
|
+
contentDigest: createContentDigest(disclaimer),
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
createNode(node);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
468
507
|
}
|
|
469
508
|
};
|
|
470
|
-
|
|
471
509
|
exports.createPages = async ({ actions, store }, pluginOptions) => {
|
|
472
|
-
const { brand, environment } = pluginOptions;
|
|
510
|
+
const { brand, environment, debug } = pluginOptions;
|
|
473
511
|
const { createSlice, createPage } = actions;
|
|
474
512
|
const siteRoot = store.getState().program.directory;
|
|
475
513
|
if (environment === "dev") {
|
|
@@ -555,7 +593,7 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
|
|
|
555
593
|
},
|
|
556
594
|
});
|
|
557
595
|
|
|
558
|
-
console.log(sliceId);
|
|
596
|
+
debug && console.log(sliceId);
|
|
559
597
|
b["sliceId"] = sliceId;
|
|
560
598
|
return b;
|
|
561
599
|
})
|
package/package.json
CHANGED
package/src/sliceWrapper.tsx
CHANGED
|
@@ -31,7 +31,10 @@ export default function SliceWrapper({
|
|
|
31
31
|
<Component
|
|
32
32
|
{...props}
|
|
33
33
|
trustPilotData={data.allTrustPilotReviews.edges[0].node}
|
|
34
|
+
/* CHECK_DISCLAIMERS_START */
|
|
34
35
|
disclaimers={data.allDisclaimers}
|
|
36
|
+
/* CHECK_DISCLAIMERS_END */
|
|
37
|
+
/* CHECK_BLOGS_START */
|
|
35
38
|
blogs={{
|
|
36
39
|
sliderBlogs: {
|
|
37
40
|
...data.sliderBlogs,
|
|
@@ -40,6 +43,7 @@ export default function SliceWrapper({
|
|
|
40
43
|
...data.allBlogs,
|
|
41
44
|
},
|
|
42
45
|
}}
|
|
46
|
+
/* CHECK_BLOGS_END */
|
|
43
47
|
/>
|
|
44
48
|
);
|
|
45
49
|
}
|
|
@@ -77,15 +81,18 @@ export const TrustPilotQuery = graphql`
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
84
|
+
# CHECK_DISCLAIMERS_START
|
|
80
85
|
allDisclaimers: allAttainLabsCmsDisclaimers {
|
|
81
|
-
|
|
86
|
+
edges {
|
|
82
87
|
node {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
content
|
|
89
|
+
published
|
|
90
|
+
order
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
}
|
|
94
|
+
# CHECK_DISCLAIMERS_END
|
|
95
|
+
# CHECK_BLOGS_START
|
|
89
96
|
allBlogs: allAttainLabsCmsBlogs {
|
|
90
97
|
edges {
|
|
91
98
|
node {
|
|
@@ -149,5 +156,6 @@ export const TrustPilotQuery = graphql`
|
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
}
|
|
159
|
+
# CHECK_BLOGS_END
|
|
152
160
|
}
|
|
153
161
|
`;
|