-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
39 lines (34 loc) · 1 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require('path')
const { PAGES } = require('./src/config')
// Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = async ({ actions }) => {
const { createPage, createRedirect } = actions
// Create pages for each page in the config file.
PAGES.forEach(page => {
const context = { ...page }
;['path', 'component'].forEach(key => {
delete context[key]
})
createPage({
path: page.path,
component: path.resolve(page.component),
context,
})
if (page.alternativePaths)
page.alternativePaths.forEach(fromPath => {
console.log(`Redirecting from ${fromPath} to ${page.path}`)
createRedirect({
fromPath,
isPermanent: true,
redirectInBrowser: true,
toPath: page.path,
})
})
})
}