-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
48 lines (46 loc) · 1.07 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
// GET all posts
async function getMdxForPosts({ actions, graphql }) {
const { data } = await graphql(`
query MyQuery {
allMdx {
edges {
node {
frontmatter {
title
slug
tags
}
body
id
}
}
}
}
`);
data.allMdx.edges.forEach((post) => {
const { id } = post.node;
const { slug } = post.node.frontmatter;
actions.createPage({
path: `posts/${slug}`,
component: require.resolve('./src/templates/post-template.jsx'),
context: {
id,
pathPrefix: '',
},
});
});
}
exports.createPages = async ({ graphql, actions }) => {
await Promise.all([getMdxForPosts({ graphql, actions })]);
};
// Create additional fields for GraphQl query
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === 'Mdx') {
createNodeField({
node,
name: 'collection',
value: getNode(node.parent).sourceInstanceName,
});
}
};