1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-11-16 01:55:15 +01:00
portfolio/gatsby-node.js

96 lines
2.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-05-14 01:50:11 +02:00
// Intersection Observer polyfill
// requires `npm install intersection-observer`
2018-05-04 21:48:09 +02:00
// https://github.com/gatsbyjs/gatsby/issues/2288#issuecomment-334467821
exports.modifyWebpackConfig = ({ config, stage }) => {
if (stage === 'build-html') {
config.loader('null', {
test: /intersection-observer/,
2018-05-22 22:51:41 +02:00
loader: 'null-loader'
2018-05-04 21:48:09 +02:00
})
}
}
2018-04-07 14:18:06 +02:00
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators
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
}
2018-04-15 21:08:59 +02:00
previous {
title
slug
2018-05-04 14:00:21 +02:00
img {
id
childImageSharp {
2018-05-05 20:59:24 +02:00
sizes(maxWidth: 500, quality: 80) {
2018-05-04 14:00:21 +02:00
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
originalImg
originalName
}
}
}
2018-04-15 21:08:59 +02:00
}
next {
title
slug
2018-05-04 14:00:21 +02:00
img {
id
childImageSharp {
2018-05-05 20:59:24 +02:00
sizes(maxWidth: 500, quality: 80) {
2018-05-04 14:00:21 +02:00
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
originalImg
originalName
}
}
}
2018-04-15 21:08:59 +02:00
}
2018-04-07 14:18:06 +02:00
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors)
}
2018-05-05 00:17:26 +02:00
result.data.allProjectsYaml.edges.forEach(
2018-04-30 01:18:54 +02:00
({ node, previous, next }) => {
2018-04-15 21:08:59 +02:00
const slug = node.slug
2018-04-07 14:18:06 +02:00
2018-04-15 21:08:59 +02:00
createPage({
2018-04-22 18:56:31 +02:00
path: slug,
2018-04-15 21:08:59 +02:00
component: template,
context: {
slug,
previous,
2018-05-22 22:51:41 +02:00
next
}
2018-04-15 21:08:59 +02:00
})
}
)
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
})
}