-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
executable file
·56 lines (48 loc) · 1.37 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
const path = require("path");
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allMdx {
edges {
node {
id
frontmatter {
slug
type
}
}
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query')
}
// create blog post pages
const posts = result.data.allMdx.edges
createPage({
path: `/blog`,
component: path.resolve(`src/templates/blog.js`),
// you can use the values in this context in
// our page layout component
context: { edges: posts },
})
createPage({
path: `/projects`,
component: path.resolve(`src/templates/projects.js`),
// you can use the values in this context in
// our page layout component
context: { edges: posts },
})
// call `createPage` for each result
posts.forEach(({ node }) => {
createPage({
path: node.frontmatter.type === "about" ? "/about" : `/article/${node.frontmatter.slug}`,
component: node.frontmatter.type === "about" ? path.resolve(`src/templates/about.js`) : path.resolve(`src/templates/post.js`),
// you can use the values in this context in
// our page layout component
context: { id: node.id },
})
})
};