forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
43 lines (36 loc) · 1.18 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
'use strict'
/*
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const fs = require('fs')
const yaml = require('js-yaml')
const envFlag = require('node-env-flag')
const includeDevPages = envFlag(process.env.INCLUDE_DEV_PAGES, true)
const { categories } = yaml.safeLoad(
fs.readFileSync('./service-definitions.yml', 'utf8')
)
// Often in Gatsby context gets piped through GraphQL, but GraphQL adds
// unnecessary complexity here, so this uses the programmatic API.
// https://www.gatsbyjs.org/docs/using-gatsby-without-graphql/#the-approach-fetch-data-and-use-gatsbys-createpages-api
async function createPages({ actions: { createPage } }) {
if (includeDevPages) {
createPage({
path: '/dev/logos',
component: require.resolve(
'./frontend/components/development/logo-page.tsx'
),
})
}
categories.forEach(category => {
const { id } = category
createPage({
path: `/category/${id}`,
component: require.resolve('./frontend/components/main'),
// `context` provided here becomes `props.pageContext` on the page.
context: { category },
})
})
}
module.exports = { createPages }