1 | const {createFilePath} = require('gatsby-source-filesystem')
|
2 | const path = require('path')
|
3 |
|
4 | exports.onCreateNode = ({node, getNode, actions}) => {
|
5 | const {createNodeField} = actions
|
6 | if (node.internal.type === 'MarkdownRemark') {
|
7 | const slug = createFilePath({node, getNode, basePath: 'content', trailingSlash: false})
|
8 | createNodeField({
|
9 | node,
|
10 | name: 'slug',
|
11 | value: slug
|
12 | })
|
13 | }
|
14 | }
|
15 |
|
16 | exports.createPages = ({graphql, actions}) => {
|
17 | const {createPage} = actions
|
18 | return graphql(`
|
19 | {
|
20 | allMarkdownRemark {
|
21 | edges {
|
22 | node {
|
23 | id
|
24 | fields {
|
25 | slug
|
26 | }
|
27 | html
|
28 | }
|
29 | }
|
30 | }
|
31 | }
|
32 | `).then(result => {
|
33 | result.data.allMarkdownRemark.edges.forEach(({node}) => {
|
34 | createPage({
|
35 | path: node.fields.slug,
|
36 | component: path.resolve('./src/templates/Page.js'),
|
37 | context: {
|
38 | slug: node.fields.slug
|
39 | }
|
40 | })
|
41 | })
|
42 | })
|
43 | }
|