1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00
portfolio/gatsby-node.js

66 lines
1.4 KiB
JavaScript

const path = require('path')
// https://github.com/saschajullmann/gatsby-starter-gatsbythemes/blob/master/gatsby-node.js
exports.modifyWebpackConfig = ({ config, stage }) => {
switch (stage) {
case 'develop':
config.preLoader('eslint-loader', {
test: /\.(js|jsx)$/,
exclude: /node_modules/,
})
break
}
return config
}
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
const template = path.resolve('src/templates/Project.jsx')
resolve(graphql(`
{
allProjectsJson {
edges {
node {
slug
}
previous {
title
slug
}
next {
title
slug
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors)
}
result.data.allProjectsJson.edges.forEach(
({ node, previous, next }) => {
const slug = node.slug
createPage({
path: slug,
component: template,
context: {
slug,
previous,
next,
},
})
}
)
resolve()
}))
})
}