-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
50 lines (45 loc) · 1.2 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
const path = require('path')
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
const result = await graphql(`
query {
allMdx(sort: {order: DESC, fields: frontmatter___date}) {
edges {
node {
id
frontmatter {
slug,
title
coverAlt
cover {
childImageSharp {
gatsbyImageData(
layout: CONSTRAINED
placeholder: BLURRED
formats: [AUTO, WEBP, AVIF]
)
}
}
}
}
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query')
}
const posts = result.data.allMdx.edges
posts.forEach(({ node }, index) => {
createPage({
path: node.frontmatter.slug,
component: path.resolve(`./src/modules/layout/PostLayout.jsx`),
context: {
id: node.id,
postIndex: index,
prev: index === 0 ? null : posts[index - 1].node,
next: index === posts.length - 1 ? null : posts[index + 1].node
},
})
})
}