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