-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
60 lines (58 loc) · 1.36 KB
/
gatsby-node.js
File metadata and controls
60 lines (58 loc) · 1.36 KB
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
const path = require("path")
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
const { data } = await graphql(`
query {
tours: allContentfulTour {
edges {
node {
slug
}
}
}
posts: allContentfulPost {
edges {
node {
slug
}
}
}
}
`)
data.tours.edges.forEach(({ node }) => {
createPage({
path: `/tours/${node.slug}`,
component: path.resolve("./src/templates/tour-template.js"),
context: {
slug: node.slug,
},
})
})
data.posts.edges.forEach(({ node }) => {
createPage({
path: `/blog/${node.slug}`,
component: path.resolve("./src/templates/blog-template.js"),
context: {
slug: node.slug,
},
})
})
// amount of posts
const posts = data.posts.edges
// posts per page
const postPerPage = 5
// amount of pages
const numPages = Math.ceil(posts.length / postPerPage)
Array.from({ length: numPages }).forEach((_, index) => {
createPage({
path: index === 0 ? `/blogs/` : `/blogs/${index + 1}`,
component: path.resolve("./src/templates/blog-list-template.js"),
context: {
limit: postPerPage,
skip: index * postPerPage,
numPages,
currentPage: index + 1,
},
})
})
}