gatsby-attainlabs-cms 1.0.13 → 1.0.15
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 +11 -11
- package/package.json +1 -1
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,
|
|
14
|
+
const createPage = async (blocks, pageUrl, id) => {
|
|
15
15
|
// Validate input parameters
|
|
16
|
-
if (!Array.isArray(blocks) || !
|
|
16
|
+
if (!Array.isArray(blocks) || !pageUrl || !id) {
|
|
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,
|
|
21
|
+
const generateSlices = (blocks, pageUrl, id) => {
|
|
22
22
|
return blocks
|
|
23
23
|
.map(
|
|
24
24
|
(b) =>
|
|
25
|
-
`<Slice alias="block--${
|
|
25
|
+
`<Slice alias="block--${pageUrl}--${b.props.component.name}--${id}" />`
|
|
26
26
|
)
|
|
27
27
|
.join("\n");
|
|
28
28
|
};
|
|
@@ -44,7 +44,7 @@ const createPage = async (blocks, slug, id) => {
|
|
|
44
44
|
const Page = () => {
|
|
45
45
|
return (
|
|
46
46
|
<Layout>
|
|
47
|
-
${generateSlices(blocks,
|
|
47
|
+
${generateSlices(blocks, pageUrl, id)}
|
|
48
48
|
</Layout>
|
|
49
49
|
);
|
|
50
50
|
};
|
|
@@ -131,7 +131,7 @@ exports.onPreInit = async (_, pluginOptions) => {
|
|
|
131
131
|
localTargets.forEach(({ localPath, targetPath }) => {
|
|
132
132
|
if (!fs.existsSync(targetPath)) {
|
|
133
133
|
fs.mkdirSync(targetPath, { recursive: true });
|
|
134
|
-
console.log(`📂 Created directory: ${targetPath}`);
|
|
134
|
+
// console.log(`📂 Created directory: ${targetPath}`);
|
|
135
135
|
}
|
|
136
136
|
const fileName = path.basename(localPath);
|
|
137
137
|
const destFile = path.join(targetPath, fileName);
|
|
@@ -211,7 +211,7 @@ exports.onPreInit = async (_, pluginOptions) => {
|
|
|
211
211
|
|
|
212
212
|
if (!fs.existsSync(destDir)) {
|
|
213
213
|
fs.mkdirSync(destDir, { recursive: true });
|
|
214
|
-
console.log(`📂 Created directory: ${destDir}`);
|
|
214
|
+
// console.log(`📂 Created directory: ${destDir}`);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
const doRequest = (url) => {
|
|
@@ -287,7 +287,7 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
|
|
|
287
287
|
blocks: {
|
|
288
288
|
content,
|
|
289
289
|
root: {
|
|
290
|
-
props: {
|
|
290
|
+
props: { pageUrl },
|
|
291
291
|
},
|
|
292
292
|
},
|
|
293
293
|
},
|
|
@@ -298,7 +298,7 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
|
|
|
298
298
|
await Promise.all(
|
|
299
299
|
content.map(async (b) => {
|
|
300
300
|
const name = b.props.component.name;
|
|
301
|
-
const blockId = `block--${
|
|
301
|
+
const blockId = `block--${pageUrl}--${name}--${id}`;
|
|
302
302
|
console.log(`Creating slice: ${blockId}`);
|
|
303
303
|
// here we could await something per slice if needed later
|
|
304
304
|
createSlice({
|
|
@@ -315,8 +315,8 @@ exports.createPages = async ({ actions, store }, pluginOptions) => {
|
|
|
315
315
|
})
|
|
316
316
|
);
|
|
317
317
|
|
|
318
|
-
const pageSource = await createPage(content,
|
|
319
|
-
const outPath = path.join(siteRoot, "src/pages", `${
|
|
318
|
+
const pageSource = await createPage(content, pageUrl, id);
|
|
319
|
+
const outPath = path.join(siteRoot, "src/pages", `${pageUrl}.tsx`);
|
|
320
320
|
// Generate the page itself
|
|
321
321
|
await fse.outputFile(outPath, pageSource);
|
|
322
322
|
console.log(`✅ Wrote page to ${outPath}`);
|