gatsby-attainlabs-cms 1.0.17 → 1.0.18

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.
@@ -3,6 +3,8 @@ interface SliceWrapperProps {
3
3
  componentPath: string;
4
4
  [key: string]: any;
5
5
  };
6
+ data: any;
6
7
  }
7
- export default function SliceWrapper({ sliceContext }: SliceWrapperProps): import("react/jsx-runtime").JSX.Element | null;
8
+ export default function SliceWrapper({ sliceContext, data, }: SliceWrapperProps): import("react/jsx-runtime").JSX.Element | null;
9
+ export declare const TrustPilotQuery: import("gatsby").StaticQueryDocument;
8
10
  export {};
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { graphql } from "gatsby";
2
3
  import { CMS_COMPONENTS } from "./map";
3
- export default function SliceWrapper({ sliceContext }) {
4
+ export default function SliceWrapper({ sliceContext, data, }) {
4
5
  const { componentPath, ...props } = sliceContext;
5
6
  const pathFormatted = componentPath
6
7
  .replace("src/cms/components//", "")
@@ -11,5 +12,40 @@ export default function SliceWrapper({ sliceContext }) {
11
12
  console.warn(`Component "${pathFormatted}" not found in CMS_COMPONENTS`);
12
13
  return null;
13
14
  }
14
- return _jsx(Component, { ...props });
15
+ return (_jsx(Component, { ...props, trustPilotData: data.allTrustPilotReviews.edges[0].node }));
15
16
  }
17
+ export const TrustPilotQuery = graphql `
18
+ query {
19
+ allTrustPilotReviews {
20
+ edges {
21
+ node {
22
+ recentReviews {
23
+ reviews {
24
+ numberOfLikes
25
+ stars
26
+ text
27
+ title
28
+ createdAt
29
+ isVerified
30
+ reviewVerificationLevel
31
+ consumer {
32
+ displayName
33
+ }
34
+ }
35
+ }
36
+ businessData {
37
+ score {
38
+ stars
39
+ trustScore
40
+ }
41
+ displayName
42
+ numberOfReviews {
43
+ total
44
+ usedForTrustScoreCalculation
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ }
51
+ `;
package/gatsby-node.js CHANGED
@@ -11,18 +11,18 @@ const brands = {
11
11
  "Attain Finance": "attainfinance",
12
12
  };
13
13
 
14
- const createPage = async (blocks, pageUrl, id) => {
14
+ const createPage = async (blocks, pageUrl) => {
15
15
  // Validate input parameters
16
- if (!Array.isArray(blocks) || !pageUrl || !id) {
16
+ if (!Array.isArray(blocks) || !pageUrl) {
17
17
  throw new Error("Invalid parameters passed to createPage.");
18
18
  }
19
19
 
20
20
  // Helper function to generate Slice components
21
- const generateSlices = (blocks, pageUrl, id) => {
21
+ const generateSlices = (blocks, id) => {
22
22
  return blocks
23
23
  .map(
24
24
  (b) =>
25
- `<Slice alias="block--${pageUrl}--${b.props.component.name}--${id}" />`
25
+ `<Slice alias="${b.sliceId}" />`
26
26
  )
27
27
  .join("\n");
28
28
  };
@@ -44,7 +44,7 @@ const createPage = async (blocks, pageUrl, id) => {
44
44
  const Page = () => {
45
45
  return (
46
46
  <Layout>
47
- ${generateSlices(blocks, pageUrl, id)}
47
+ ${generateSlices(blocks, pageUrl)}
48
48
  </Layout>
49
49
  );
50
50
  };
@@ -123,7 +123,7 @@ exports.onPreInit = async (_, pluginOptions) => {
123
123
  },
124
124
  {
125
125
  repoPath: "/apps/cms/src/cms/editors/visual-block-editor/core/",
126
- localBasePath: path.resolve("./src/cms/components/"),
126
+ localBasePath: path.resolve("./src/cms/"),
127
127
  },
128
128
  {
129
129
  repoPath: `/apps/cms/src/gatsby-plugin-theme-ui/${brands[brand]}`,
@@ -250,8 +250,12 @@ exports.onPreInit = async (_, pluginOptions) => {
250
250
  res.pipe(fileStream);
251
251
  fileStream.on("finish", () => {
252
252
  fileStream.close(() => {
253
- const generatedComment =
254
- "// GENERATED FILE // This file is automatically generated by the AttainLabs CMS plugin. Do not edit this file directly.\n";
253
+ const ext = path.extname(destFile).toLowerCase();
254
+ let generatedComment = "";
255
+ if (ext === ".ts" || ext === ".tsx" || ext === ".js" || ext === ".jsx") {
256
+ generatedComment =
257
+ "// GENERATED FILE // This file is automatically generated by the AttainLabs CMS plugin. Do not edit this file directly.\n";
258
+ }
255
259
  const fileContent = fs.readFileSync(tmpFile, "utf8");
256
260
  fs.writeFileSync(destFile, generatedComment + fileContent);
257
261
 
@@ -393,26 +397,28 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
393
397
  if (published) {
394
398
  //Generate page's blocks slices
395
399
  await Promise.all(
396
- content.map(async (b) => {
400
+ content.map(async (b) => {
397
401
  const name = b.props.component.name;
398
- const blockId = `block--${pageUrl}--${name}--${id}`;
399
- console.log(`Creating slice: ${blockId}`);
402
+ const sliceId = `block--${pageUrl}--${name}--${id}--${crypto.randomUUID()}`;
403
+ console.log(`Creating slice: ${sliceId}`);
400
404
  // here we could await something per slice if needed later
401
405
  createSlice({
402
- id: blockId,
406
+ id: sliceId,
403
407
  component: path.resolve(
404
408
  siteRoot,
405
409
  "src/cms/components/sliceWrapper.tsx"
406
410
  ),
407
411
  context: {
408
- componentPath: `./src/cms/components/${b.props.component.path}/index.tsx`,
412
+ componentPath: `./src/cms/components${b.props.component.path}/index.tsx`,
409
413
  ...b.props,
410
414
  },
411
415
  });
416
+ b["sliceId"] = sliceId; // attach sliceId to block for later use
417
+ return b;
412
418
  })
413
419
  );
414
420
 
415
- const pageSource = await createPage(content, pageUrl, id);
421
+ const pageSource = await createPage(content, pageUrl);
416
422
  const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
417
423
  // Generate the page itself
418
424
  await fse.outputFile(outPath, pageSource);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  // GENERATED FILE // This file is automatically generated by the AttainLabs CMS plugin. Do not edit this file directly.
2
2
 
3
3
  import React from "react";
4
- import type { SliceComponentProps } from "gatsby";
4
+ import { graphql, type SliceComponentProps } from "gatsby";
5
5
  import { CMS_COMPONENTS } from "./map";
6
6
 
7
7
  interface SliceWrapperProps {
@@ -9,11 +9,14 @@ interface SliceWrapperProps {
9
9
  componentPath: string;
10
10
  [key: string]: any;
11
11
  };
12
+ data: any;
12
13
  }
13
14
 
14
- export default function SliceWrapper({ sliceContext }: SliceWrapperProps) {
15
+ export default function SliceWrapper({
16
+ sliceContext,
17
+ data,
18
+ }: SliceWrapperProps) {
15
19
  const { componentPath, ...props } = sliceContext;
16
-
17
20
  const pathFormatted = componentPath
18
21
  .replace("src/cms/components//", "")
19
22
  .replace(/^.\//, "")
@@ -24,5 +27,46 @@ export default function SliceWrapper({ sliceContext }: SliceWrapperProps) {
24
27
  return null;
25
28
  }
26
29
 
27
- return <Component {...props} />;
30
+ return (
31
+ <Component
32
+ {...props}
33
+ trustPilotData={data.allTrustPilotReviews.edges[0].node}
34
+ />
35
+ );
28
36
  }
37
+
38
+ export const TrustPilotQuery = graphql`
39
+ query {
40
+ allTrustPilotReviews {
41
+ edges {
42
+ node {
43
+ recentReviews {
44
+ reviews {
45
+ numberOfLikes
46
+ stars
47
+ text
48
+ title
49
+ createdAt
50
+ isVerified
51
+ reviewVerificationLevel
52
+ consumer {
53
+ displayName
54
+ }
55
+ }
56
+ }
57
+ businessData {
58
+ score {
59
+ stars
60
+ trustScore
61
+ }
62
+ displayName
63
+ numberOfReviews {
64
+ total
65
+ usedForTrustScoreCalculation
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ `;