Skip to content

Commit 594a55d

Browse files
committed
done with the tutorial
1 parent fd40d35 commit 594a55d

File tree

9 files changed

+1109
-8
lines changed

9 files changed

+1109
-8
lines changed

gatsby-src/gatsby-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
},
55
plugins: [
66
`gatsby-plugin-glamor`,
7+
`gatsby-transformer-remark`,
78
{
89
resolve: `gatsby-source-filesystem`,
910
options: {

gatsby-src/gatsby-node.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const path = require(`path`);
2+
const { createFilePath } = require(`gatsby-source-filesystem`);
3+
4+
exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
5+
const { createNodeField } = boundActionCreators
6+
if (node.internal.type === `MarkdownRemark`) {
7+
const slug = createFilePath({ node, getNode, basePath: `pages` })
8+
createNodeField({
9+
node,
10+
name: `slug`,
11+
value: slug,
12+
})
13+
}
14+
};
15+
16+
exports.createPages = ({ graphql, boundActionCreators }) => {
17+
const { createPage } = boundActionCreators
18+
return new Promise((resolve, reject) => {
19+
graphql(`
20+
{
21+
allMarkdownRemark {
22+
edges {
23+
node {
24+
fields {
25+
slug
26+
}
27+
}
28+
}
29+
}
30+
}
31+
`).then(result => {
32+
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
33+
createPage({
34+
path: node.fields.slug,
35+
component: path.resolve(`./src/templates/blog-post.js`),
36+
context: {
37+
// Data passed to context is available in page queries as GraphQL variables.
38+
slug: node.fields.slug,
39+
},
40+
})
41+
})
42+
resolve()
43+
})
44+
})
45+
};

0 commit comments

Comments
 (0)