gatsby-attainlabs-cms 1.0.46 → 1.0.47

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.
@@ -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, disclaimers: data.allDisclaimers, blogs: {
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
- edges {
64
+ edges {
59
65
  node {
60
- content
61
- published
62
- order
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
@@ -101,6 +101,7 @@ exports.onPreInit = async (_, pluginOptions) => {
101
101
  azureBranch,
102
102
  personalAccessToken: patOption,
103
103
  environment,
104
+ fetch: fetchConfig,
104
105
  } = pluginOptions;
105
106
 
106
107
  // Try env first, then plugin option fallback
@@ -183,8 +184,38 @@ exports.onPreInit = async (_, pluginOptions) => {
183
184
  }
184
185
  const fileName = path.basename(localPath);
185
186
  const destFile = path.join(targetPath, fileName);
186
- fs.copyFileSync(localPath, destFile);
187
- console.log(`✅ Copied ${destFile}`);
187
+
188
+ if (fileName === "sliceWrapper.tsx") {
189
+ let content = fs.readFileSync(localPath, "utf8");
190
+
191
+ if (!fetchConfig || !fetchConfig.includes("blogs")) {
192
+ content = content.replace(
193
+ /# CHECK_BLOGS_START[\s\S]*?# CHECK_BLOGS_END/g,
194
+ ""
195
+ );
196
+ content = content.replace(
197
+ /\/\* CHECK_BLOGS_START \*\/[\s\S]*?\/\* CHECK_BLOGS_END \*\//g,
198
+ ""
199
+ );
200
+ }
201
+
202
+ if (!fetchConfig || !fetchConfig.includes("disclaimers")) {
203
+ content = content.replace(
204
+ /# CHECK_DISCLAIMERS_START[\s\S]*?# CHECK_DISCLAIMERS_END/g,
205
+ ""
206
+ );
207
+ content = content.replace(
208
+ /\/\* CHECK_DISCLAIMERS_START \*\/[\s\S]*?\/\* CHECK_DISCLAIMERS_END \*\//g,
209
+ ""
210
+ );
211
+ }
212
+
213
+ fs.writeFileSync(destFile, content);
214
+ console.log(`✅ Copied and transformed ${destFile}`);
215
+ } else {
216
+ fs.copyFileSync(localPath, destFile);
217
+ console.log(`✅ Copied ${destFile}`);
218
+ }
188
219
  });
189
220
 
190
221
  // Loop through targets
@@ -321,7 +352,12 @@ exports.sourceNodes = async (
321
352
  pluginOptions
322
353
  ) => {
323
354
  const { createNode } = actions;
324
- const { trustpilotApiKey, brand, environment } = pluginOptions;
355
+ const {
356
+ trustpilotApiKey,
357
+ brand,
358
+ environment,
359
+ fetch: fetchConfig,
360
+ } = pluginOptions;
325
361
  const apiKey = process.env.TRUSTPILOT_API_KEY || trustpilotApiKey;
326
362
 
327
363
  if (environment === "dev") {
@@ -410,7 +446,6 @@ exports.sourceNodes = async (
410
446
  }
411
447
 
412
448
  // Blogs node creation
413
-
414
449
  const fetchData = async () => {
415
450
  try {
416
451
  const response = await fetch(
@@ -427,44 +462,46 @@ exports.sourceNodes = async (
427
462
  }
428
463
  };
429
464
 
430
- const firebaseData = await fetchData();
431
-
432
- const allBlogs = getAllBlogs(firebaseData.pages);
433
-
434
- for (const blog of allBlogs) {
435
- const id = createNodeId(`attain-cms-blog-${blog.id}`);
436
- const node = {
437
- ...blog,
438
- id,
439
- _id: blog.id,
440
- parent: null,
441
- children: [],
442
- internal: {
443
- type: "AttainLabsCmsBlogs",
444
- contentDigest: createContentDigest(blog),
445
- },
446
- };
447
- createNode(node);
448
- }
449
-
450
- // Disclaimers Source Node
451
-
452
- const allDisclaimers = Object.values(firebaseData.disclaimers);
465
+ if (fetchConfig) {
466
+ const firebaseData = await fetchData();
467
+ if (fetchConfig.includes("blogs")) {
468
+ const allBlogs = getAllBlogs(firebaseData.pages);
469
+ for (const blog of allBlogs) {
470
+ const id = createNodeId(`attain-cms-blog-${blog.id}`);
471
+ const node = {
472
+ ...blog,
473
+ id,
474
+ _id: blog.id,
475
+ parent: null,
476
+ children: [],
477
+ internal: {
478
+ type: "AttainLabsCmsBlogs",
479
+ contentDigest: createContentDigest(blog),
480
+ },
481
+ };
482
+ createNode(node);
483
+ }
484
+ }
453
485
 
454
- for (const disclaimer of allDisclaimers) {
455
- const id = createNodeId(`attain-cms-disclaimer-${disclaimer.id}`);
456
- const node = {
457
- ...disclaimer,
458
- id,
459
- _id: disclaimer.id,
460
- parent: null,
461
- children: [],
462
- internal: {
463
- type: "AttainLabsCmsDisclaimers",
464
- contentDigest: createContentDigest(disclaimer),
465
- },
466
- };
467
- createNode(node);
486
+ // Disclaimers Source Node
487
+ if (fetchConfig.includes("disclaimers")) {
488
+ const allDisclaimers = Object.values(firebaseData.disclaimers);
489
+ for (const disclaimer of allDisclaimers) {
490
+ const id = createNodeId(`attain-cms-disclaimer-${disclaimer.id}`);
491
+ const node = {
492
+ ...disclaimer,
493
+ id,
494
+ _id: disclaimer.id,
495
+ parent: null,
496
+ children: [],
497
+ internal: {
498
+ type: "AttainLabsCmsDisclaimers",
499
+ contentDigest: createContentDigest(disclaimer),
500
+ },
501
+ };
502
+ createNode(node);
503
+ }
504
+ }
468
505
  }
469
506
  };
470
507
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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
- edges {
86
+ edges {
82
87
  node {
83
- content
84
- published
85
- order
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
  `;