-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
53 lines (49 loc) · 1.36 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
const path = require(`path`)
const GetSlug = (node) => {
if (node.slug != null) {
return node.slug
} else {
return node.title
}
}
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const PostTemplate = path.resolve(`src/templates/post.tsx`)
const EventTemplate = path.resolve(`src/templates/event.tsx`)
const result = await graphql(`
query {
allContentfulPost(filter: {hidden: {ne: true}}) {
nodes {
title
contentful_id
slug
}
}
allContentfulEvent(filter: {hidden: {ne: true}}) {
nodes {
title
contentful_id
slug
}
}
}
`)
result.data.allContentfulPost.nodes.forEach(node => {
createPage({
path: `post/${GetSlug(node)}`,
component: PostTemplate,
context: {
contentful_id: node.contentful_id,
},
})
})
result.data.allContentfulEvent.nodes.forEach(node => {
createPage({
path: `event/${GetSlug(node)}`,
component: EventTemplate,
context: {
contentful_id: node.contentful_id,
},
})
})
}