-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
50 lines (46 loc) · 1.38 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 { createFilePath } = require('gatsby-source-filesystem')
const path = require(`path`)
// Create permalink nodes in GraphQL...
exports.onCreateNode = ({ node, getNode, actions }) => {
if (node.internal.type === 'MarkdownRemark') {
const { createNodeField } = actions;
const permalink = createFilePath( { node, getNode, basePath: 'posts' } );
createNodeField( {
node,
name: 'permalink',
value: permalink
});
}
}
// Create blog post pages programmatically at build time...
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve('./src/templates/posting.js')
return graphql(`
query loadPagesQuery ($limit: Int!) {
allMarkdownRemark(limit: $limit) {
edges {
node {
fields {
permalink
}
}
}
}
}
`, { limit: 1000 }).then(result => {
if (result.errors) {
throw result.errors
}
// Create blog post pages.
result.data.allMarkdownRemark.edges.forEach(edge => {
createPage({
path: `${edge.node.fields.permalink}`,
component: blogPostTemplate,
context: {
permalink: edge.node.fields.permalink,
},
})
})
})
}