-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
41 lines (38 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/node-apis/
*/
import path from 'path'
// Grab list of dev workspaces and create pages from them.
async function turnDevWorkspacesIntoPages({ graphql, actions }) {
// 1. Get a template for this page
const devWorkspacesTemplate = path.resolve('./src/templates/DevWorkspace.js')
// 2. Query all workspaces
const { data } = await graphql(`
query {
devWorkspaces: allMarkdownRemark {
edges {
node {
id
}
}
}
}
`)
// 3. Loop over each blog and create a page for it.
data.devWorkspaces.edges.forEach(devWorkspace => {
actions.createPage({
path: `/workspaces/${devWorkspace.node.id}`,
component: devWorkspacesTemplate,
context: {
slug: `${devWorkspace.node.id}`,
},
})
})
}
export async function createPages(params) {
// Create pages dynamically
// Wait for all promises to be resolved before finishing this function.
await Promise.all([turnDevWorkspacesIntoPages(params)])
}