-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
101 lines (94 loc) · 2.72 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require("path");
const createPaginatedPages = require("gatsby-paginate");
// exports.createLayouts = ({ graphql, boundActionCreators }) => {
// return new Promise((resolve, reject) => {
// const addressBlock = path.resolve('src/templates/AddressBlock.js')
// resolve(
// graphql(
// `
// query {
// allContentfulContact {
// edges {
// node {
// hours {
// hours
// }
// phone
// email
// }
// }
// }
// }
// `
// )
// ).then(result => {
// if(result.errors) {
// reject(result.errors)
// }
// console.log(result)
// })
// })
// }
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
const eventDetailTemplate = path.resolve(`src/templates/EventDetail.js`)
const upcomingEventsTemplate = path.resolve('src/templates/UpcomingEventsList.js')
// Query for markdown nodes to use in creating pages.
resolve(
graphql(
`
query showSummary {
allContentfulShow (
sort: { fields: [date], order:DESC }
) {
edges {
node {
id
name
date
slug
coverPrice
image {
file {
url
}
}
}
}
}
}
`
).then(result => {
if (result.errors) {
reject(result.errors)
}
createPaginatedPages({
edges: result.data.allContentfulShow.edges,
createPage: createPage,
pageTemplate: upcomingEventsTemplate,
pageLength: 5, // This is optional and defaults to 10 if not used
pathPrefix: "", // This is optional and defaults to an empty string if not used
context: { showCount: result.data.allContentfulShow.edges.length} // This is optional and defaults to an empty object if not used
});
// Create blog post pages.
result.data.allContentfulShow.edges.forEach(edge => {
createPage({
path: `${edge.node.slug}`, // required
component: eventDetailTemplate,
context: {
slug: edge.node.slug,
},
})
})
return
})
)
})
}