-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
53 lines (48 loc) · 1.35 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 pagination = require("gatsby-awesome-pagination")
const path = require(`path`)
// Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
const workEntry = path.resolve(`src/templates/work.js`)
const workIndex = path.resolve(`src/templates/index.js`)
resolve(
graphql(
`
{
allNodeObra(filter: { status: { eq: true } }) {
nodes {
drupal_internal__nid
title
}
}
}
`
).then(result => {
if (result.errors) {
console.error(result.errors)
reject(result.errors)
}
const works = result.data.allNodeObra.nodes
pagination.paginate({
createPage,
items: works,
component: workIndex,
itemsPerPage: 9,
pathPrefix: `/`,
})
works.forEach(work => {
const slug = `/obres/${work.drupal_internal__nid}/`
createPage({
path: slug,
component: workEntry,
context: {
id: work.drupal_internal__nid,
},
})
})
})
)
})
}