-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
42 lines (37 loc) · 995 Bytes
/
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
const path = require('path');
const { formatDate } = require('./src/utils/dates')
exports.createPages = async ({ graphql, actions }) => {
const { data } = await graphql(`
query Events {
allPrismicEvent {
nodes {
uid
}
}
}
`);
// create event pages
data.allPrismicEvent.nodes.forEach((event) => {
actions.createPage({
path: `/events/${event.uid}`,
component: path.resolve('./src/templates/eventPage.jsx'),
context: { slug: event.uid },
});
})
};
/*
* To pass variables into graphql page queries, they must be added to the
* page context via the Create Page API. We use this date to filter events.
* gatsbyjs.com/docs/creating-and-modifying-pages/#pass-context-to-pages
*/
exports.onCreatePage = ({ page, actions }) => {
const { deletePage, createPage } = actions;
deletePage(page);
createPage({
...page,
context: {
...page.context,
date: formatDate(new Date()),
},
});
}