gatsby-attainlabs-cms 1.0.19 → 1.0.20

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.
Files changed (2) hide show
  1. package/gatsby-node.js +34 -18
  2. package/package.json +1 -1
package/gatsby-node.js CHANGED
@@ -11,14 +11,14 @@ const brands = {
11
11
  "Attain Finance": "attainfinance",
12
12
  };
13
13
 
14
- const createPage = async (blocks, pageUrl) => {
14
+ const generatePage = async (blocks) => {
15
15
  // Validate input parameters
16
- if (!Array.isArray(blocks) || !pageUrl) {
16
+ if (!Array.isArray(blocks)) {
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, id) => {
21
+ const generateSlices = (blocks) => {
22
22
  return blocks
23
23
  .map(
24
24
  (b) =>
@@ -31,20 +31,23 @@ const createPage = async (blocks, pageUrl) => {
31
31
  const pageContent = `
32
32
  /* This is a generated file by the gatsby-attainlabs-cms plugin. Any changes will be overwritten on the next build. */
33
33
  import { Slice } from "gatsby";
34
- import { SEO } from "../components/SEO";
35
- import { DefaultLayout as Layout } from "../layouts/Default/";
34
+ import SEO from "../components/SEO";
35
+ import Layout from "../layouts/Main";
36
36
 
37
- const metaTitle = "{page.root.props.title}";
38
- const metaDescription = "{page.root.props.description}";
37
+
39
38
 
40
- export const Head = () => (
41
- <SEO title={metaTitle} description={metaDescription} noIndex={true} />
42
- );
39
+ export const Head = ({ pageContext }: any) => {
40
+ const blocks = pageContext.blocks
41
+ ? pageContext.blocks
42
+ : pageContext.draft.blocks;
43
+ const { title, description } = blocks.root.props.meta;
44
+ return <SEO title={title} description={description} noIndex={true} />;
45
+ };
43
46
 
44
- const Page = () => {
47
+ const Page = ({pageContext}:any ) => {
45
48
  return (
46
49
  <Layout>
47
- ${generateSlices(blocks, pageUrl)}
50
+ ${generateSlices(blocks)}
48
51
  </Layout>
49
52
  );
50
53
  };
@@ -355,7 +358,7 @@ exports.sourceNodes = async (
355
358
  };
356
359
  exports.createPages = async ({ actions, store }, pluginOptions) => {
357
360
  const { brand, environment } = pluginOptions;
358
- const { createSlice } = actions;
361
+ const { createSlice, createPage } = actions;
359
362
  const siteRoot = store.getState().program.directory;
360
363
  if (environment === "dev") {
361
364
  console.log(
@@ -418,11 +421,24 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
418
421
  })
419
422
  );
420
423
 
421
- const pageSource = await createPage(content, pageUrl);
422
- const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
423
- // Generate the page itself
424
- await fse.outputFile(outPath, pageSource);
425
- console.log(`✅ Wrote page to ${outPath}`);
424
+ const pageSource = await generatePage(content, pageUrl);
425
+ const outPath = path.join(siteRoot, "src/cms/pages", `${pageUrl}.tsx`);
426
+
427
+ await fse.outputFile(outPath, pageSource);
428
+ await createPage({
429
+ path: pageUrl === "index" ? `/` : `/${pageUrl}`,
430
+ component: outPath, // ✅ a file path string
431
+ context: {
432
+ ...page
433
+ },
434
+ });
435
+
436
+
437
+ // const pageSource = await generatePage(content, pageUrl);
438
+ // const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
439
+ // // Generate the page itself
440
+ // await fse.outputFile(outPath, pageSource);
441
+ // console.log(`✅ Wrote page to ${outPath}`);
426
442
  }
427
443
  }
428
444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-attainlabs-cms",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",