-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
48 lines (42 loc) · 1.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
const path = require("path")
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
const result = await graphql(`
query {
allMdx(sort: { frontmatter: {date: DESC}}) {
nodes {
id
frontmatter {
date(formatString: "YYYY-MM-DD")
slug
subtitle
title
tags
}
internal {
contentFilePath
}
body
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query')
}
console.log(result.data.allMdx.nodes.length)
const posts = result.data.allMdx.nodes
posts.forEach((node, index) => {
const previousPost = posts[index - 1]
const nextPost = posts[index + 1]
createPage({
path: node.frontmatter.slug,
component: `${path.resolve(`./src/pages/posts.js`)}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
id: node.id,
prev: previousPost === undefined ? null : previousPost.id,
next: nextPost !== undefined ? nextPost.id : null,
},
})
})
}