-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
142 lines (131 loc) · 3.84 KB
/
gatsby-node.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const path = require(`path`)
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const aboutTemplate = path.resolve(`src/templates/about.js`)
const blogTemplate = path.resolve(`src/templates/blog.js`)
const categoryTemplate = path.resolve(`src/templates/category.js`)
const authorTemplate = path.resolve(`src/templates/author.js`)
const artistTemplate = path.resolve(`src/templates/artist.js`)
// const orderConfirmationTemplate = path.resolve(
// `src/templates/order-confirmation.js`
// )
// const shopTemplate = path.resolve("./src/templates/shop.js")
// const cartTemplate = path.resolve("./src/templates/cart.js")
// const productDetailsTemplate = path.resolve(
// "./src/templates/product-details.js"
// )
return graphql(`
{
blogQuery: allContentfulBlog {
edges {
node {
slug
}
}
}
categoryQuery: allContentfulBlog {
group(field: tags) {
fieldValue
totalCount
}
}
authorQuery: allContentfulBlog {
group(field: author___slug) {
fieldValue
totalCount
}
}
artistQuery: allContentfulBlog {
group(field: artist___slug) {
fieldValue
totalCount
}
}
}
`).then((result) => {
if (result.errors) {
throw result.errors
}
// const string_to_slug = str => {
// str = str.replace(/^\s+|\s+$/g, "") // trim
// str = str.toLowerCase()
// // remove accents, swap ñ for n, etc
// var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;"
// var to = "aaaaeeeeiiiioooouuuunc------"
// for (var i = 0, l = from.length; i < l; i++) {
// str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i))
// }
// str = str
// .replace(/[^a-z0-9 -]/g, "") // remove invalid chars
// .replace(/\s+/g, "-") // collapse whitespace and replace by -
// .replace(/-+/g, "-") // collapse dashes
// return str
// }
// result.data.productQuery.edges.forEach(({ node }) => {
// createPage({
// path: `/shop/${string_to_slug(node.product.name)}`,
// component: productDetailsTemplate,
// context: {
// slug: string_to_slug(node.product.name),
// sku: node.id,
// productId: node.product.id,
// },
// })
// })
result.data.blogQuery.edges.forEach((edge) => {
createPage({
path: `/blog/${edge.node.slug}`,
component: blogTemplate,
context: {
slug: edge.node.slug,
},
})
})
result.data.categoryQuery.group.forEach((tag) => {
createPage({
path: `/categories/${tag.fieldValue}`.toLowerCase(),
component: categoryTemplate,
context: {
tags: tag.fieldValue,
totalCount: tag.totalCount,
},
})
})
result.data.authorQuery.group.forEach((author) => {
createPage({
path: `/author/${author.fieldValue}`.toLowerCase(),
component: authorTemplate,
context: {
slug: author.fieldValue,
totalCount: author.totalCount,
},
})
})
result.data.artistQuery.group.forEach((artist) => {
createPage({
path: `/artist/${artist.fieldValue}`.toLowerCase(),
component: artistTemplate,
context: {
slug: artist.fieldValue,
totalCount: artist.totalCount,
},
})
})
createPage({
path: `/about`,
component: aboutTemplate,
})
// createPage({
// path: `/cart`,
// component: cartTemplate,
// })
// createPage({
// path: `/shop`,
// component: shopTemplate,
// })
// createPage({
// path: `/order-confirmation`,
// component: orderConfirmationTemplate,
// })
})
}