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

65 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-04-07 14:18:06 +02:00
const path = require('path')
2018-04-06 17:24:35 +02:00
2018-06-19 22:48:33 +02:00
// Intersection Observer polyfill
// requires `npm install intersection-observer`
// https://github.com/gatsbyjs/gatsby/issues/2288#issuecomment-334467821
2018-06-23 14:36:07 +02:00
// exports.onCreateWebpackConfig = ({ actions, loaders, stage }) => {
// const { setWebpackConfig } = actions
2018-06-19 22:48:33 +02:00
2018-06-23 14:36:07 +02:00
// if (stage === 'build-html') {
// const nullRule = {
// test: /intersection-observer/,
// use: [loaders.null()]
// }
2018-06-19 22:48:33 +02:00
2018-06-23 14:36:07 +02:00
// setWebpackConfig({
// module: {
// rules: [nullRule]
// }
// })
// }
// }
2018-06-19 22:48:33 +02:00
//
// Create project pages from projects.yml
//
2018-06-23 21:53:57 +02:00
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
2018-04-07 14:18:06 +02:00
return new Promise((resolve, reject) => {
2018-04-25 23:37:23 +02:00
const template = path.resolve('src/templates/Project.jsx')
2018-04-07 14:18:06 +02:00
2018-05-12 22:14:53 +02:00
resolve(
graphql(`
2018-04-07 14:18:06 +02:00
{
2018-05-05 00:17:26 +02:00
allProjectsYaml {
2018-04-07 14:18:06 +02:00
edges {
node {
slug
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors)
}
2018-06-19 22:48:33 +02:00
result.data.allProjectsYaml.edges.forEach(({ node }) => {
const slug = node.slug
2018-04-07 14:18:06 +02:00
2018-06-19 22:48:33 +02:00
createPage({
path: slug,
component: template,
context: {
slug
}
})
})
2018-04-07 14:18:06 +02:00
resolve()
2018-05-12 22:14:53 +02:00
})
)
2018-04-07 14:18:06 +02:00
})
}