-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
112 lines (106 loc) · 3.14 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
102
103
104
105
106
107
108
109
110
111
112
const path = require('path')
const createPaginatedPages = require('gatsby-paginate')
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
const pageTemplate = path.resolve('src/templates/page.js')
const blogPostTemplate = path.resolve('src/templates/blog-post.js')
graphql(`
{
allContentfulPage {
edges {
node {
id
slug
node_locale
}
}
}
}
`)
.then(result => {
if (result.errors) {
reject(result.errors)
}
result.data.allContentfulPage.edges.forEach(edge => {
createPage({
path: `/${edge.node.node_locale}/${edge.node.slug}/`,
component: pageTemplate,
context: {
slug: edge.node.slug,
id: edge.node.id,
langKey: edge.node.node_locale,
},
})
})
return
})
.then(() => {
graphql(`
{
allContentfulBlog {
edges {
node {
id
title
slug
node_locale
createdAt(formatString: "DD.MM.YYYY")
featuredImage {
resolutions(width: 255) {
width
height
src
srcSet
srcWebp
srcSetWebp
}
}
content {
childMarkdownRemark {
excerpt
}
}
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors)
}
createPaginatedPages({
edges: result.data.allContentfulBlog.edges,
createPage,
pageTemplate: 'src/templates/blog-index.js',
pageLength: 20,
pathPrefix: 'sk/blog',
buildPath: (index, pathPrefix) =>
index > 1 ? `${pathPrefix}/${index}` : `/${pathPrefix}`, // This is optional and this is the default
})
createPaginatedPages({
edges: result.data.allContentfulBlog.edges,
createPage,
pageTemplate: 'src/templates/blog-index.js',
pageLength: 20,
pathPrefix: 'en/blog',
buildPath: (index, pathPrefix) =>
index > 1 ? `${pathPrefix}/${index}` : `/${pathPrefix}`, // This is optional and this is the default
})
result.data.allContentfulBlog.edges.forEach(edge => {
createPage({
path: `/${edge.node.node_locale}/blog/${edge.node.slug}/`,
component: blogPostTemplate,
context: {
slug: edge.node.slug,
title: edge.node.title,
langKey: edge.node.node_locale,
},
})
})
return
})
})
resolve()
})
}