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 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
  ],
@@ -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
@@ -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
- fs.copyFileSync(localPath, destFile);
187
- console.log(`✅ Copied ${destFile}`);
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 { trustpilotApiKey, brand, environment } = pluginOptions;
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
- 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);
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
- 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);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
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
  `;