-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgatsby-node.js
More file actions
54 lines (47 loc) · 1.16 KB
/
Copy pathgatsby-node.js
File metadata and controls
54 lines (47 loc) · 1.16 KB
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
const path = require('path')
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (node.internal.type === 'MarkdownRemark') {
const parent = getNode(node.parent)
createNodeField({
node,
name: 'sourceInstanceName',
value: parent.sourceInstanceName,
})
}
}
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const result = await graphql(`
{
allMarkdownRemark(
filter: { fields: { sourceInstanceName: { eq: "languages" } } }
) {
nodes {
frontmatter {
slug
}
}
}
}
`)
if (result.errors) {
throw result.errors
}
const languageTemplate = path.resolve('./src/templates/language.js')
result.data.allMarkdownRemark.nodes.forEach(node => {
createPage({
path: `/languages/${node.frontmatter.slug}`,
component: languageTemplate,
context: {
slug: node.frontmatter.slug,
},
})
})
const installTemplate = path.resolve('./src/templates/install.js')
createPage({
path: '/install',
component: installTemplate,
context: {},
})
}