This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
createPages.js
68 lines (62 loc) · 1.73 KB
/
createPages.js
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
60
61
62
63
64
65
66
67
68
const { buildLocalePath } = require('../../utils/gatsby-node-helpers');
const locales = require('../../../config/locales');
const createPages = async ({ graphql, actions: { createPage } }) => {
const {
data: { categories, collections, products },
} = await graphql(`
{
categories: allGraphCmsCategory {
nodes {
slug
}
}
collections: allGraphCmsCollection {
nodes {
slug
}
}
products: allGraphCmsProduct {
nodes {
id: remoteId
}
}
}
`);
locales.map(locale => {
createPage({
path: buildLocalePath({ locale, path: `/` }),
component: require.resolve(`../../templates/ProductsPage.js`),
context: {
locale: locale.path,
},
});
if (categories) {
categories.nodes.forEach(({ slug }) =>
createPage({
path: buildLocalePath({ locale, path: `/categories/${slug}` }),
component: require.resolve(`../../templates/CategoryPage.js`),
context: { slug, locale: locale.path },
})
);
}
if (collections) {
collections.nodes.forEach(({ slug }) =>
createPage({
path: buildLocalePath({ locale, path: `/collections/${slug}` }),
component: require.resolve(`../../templates/CollectionPage.js`),
context: { slug, locale: locale.path },
})
);
}
if (products) {
products.nodes.forEach(({ id }) => {
createPage({
path: buildLocalePath({ locale, path: `/products/${id}` }),
component: require.resolve(`../../templates/ProductPage.js`),
context: { id, locale: locale.path },
});
});
}
});
};
module.exports = createPages;