Skip to content

Commit

Permalink
env: Add redirect config
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeYeopHan committed Oct 15, 2019
1 parent 42c6241 commit 0ee77b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions gatsby-meta-config.js
Expand Up @@ -37,4 +37,19 @@ module.exports = {
},
ga: 'UA-79845333-3',
sentryDsn: 'https://031a7d403c7d43c69b30e8f18c56ced0@sentry.io/1396146',
redirectTable: [
{ fromPath: '/react/[react]-0.-intro/', toPath: '/react/react-0-intro/' },
{
fromPath: '/react/[react]-1.-development-environment-setup/',
toPath: '/react/react-1-development-environment-setup/',
},
{
fromPath: '/react/[react]-2.-redux-architecture/',
toPath: '/react/react-2-redux-architecture/',
},
{
fromPath: '/react/[react]-3.-react-architecture/',
toPath: '/react/react-3-react-architecture/',
},
],
}
13 changes: 12 additions & 1 deletion gatsby-node.js
@@ -1,6 +1,8 @@
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)

const { redirectTable } = require('./gatsby-meta-config')

exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions

Expand Down Expand Up @@ -55,7 +57,16 @@ exports.createPages = ({ graphql, actions }) => {
}

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
const { createNodeField, createRedirect } = actions

redirectTable.forEach(({ fromPath, toPath }) =>
createRedirect({
fromPath,
toPath,
isPermanent: true,
redirectInBrowser: true,
})
)

if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode })
Expand Down

0 comments on commit 0ee77b1

Please sign in to comment.