forked from bcms/starters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.ts
59 lines (51 loc) · 1.39 KB
/
gatsby-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { NodePluginArgs } from 'gatsby';
import { BlogEntry, ProductEntry } from '@/bcms/types';
import { getBcmsMost } from 'gatsby-source-bcms';
import path from 'path';
exports.createSchemaCustomization = ({ actions }: NodePluginArgs) => {
const { createTypes } = actions;
const typeDefs = `
scalar Number
`;
createTypes(typeDefs);
};
exports.createPages = async ({ actions }: NodePluginArgs) => {
const { createPage } = actions;
// SINGLE PRODUCT PAGE
const productTemplate = path.resolve('./src/templates/product.tsx');
const bcms = getBcmsMost();
const products = (await bcms.content.entry.find(
'product',
async () => true,
)) as ProductEntry[];
if (products.length > 0) {
products.forEach((product) => {
createPage({
path: `/shop/${product.meta.en?.slug}`,
component: productTemplate,
context: {
id: product._id,
},
});
});
}
// END OF SINGLE PRODUCT PAGES
// SINGLE BLOG PAGE
const blogTemplate = path.resolve('./src/templates/blog.tsx');
const blogs = (await bcms.content.entry.find(
'blog',
async () => true,
)) as BlogEntry[];
if (blogs.length > 0) {
blogs.forEach((blog) => {
createPage({
path: `/blog/${blog.meta.en?.slug}`,
component: blogTemplate,
context: {
id: blog._id,
},
});
});
}
// END OF BLOG PRODUCT PAGES
};