1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-23 09:45:56 +01:00
blog/gatsby-node.js

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-01-08 21:59:55 +01:00
const webpack = require('webpack')
2018-11-18 23:52:57 +01:00
const { createMarkdownFields } = require('./gatsby/createMarkdownFields')
const { createExifFields } = require('./gatsby/createExifFields')
2018-10-14 02:25:24 +02:00
const {
generatePostPages,
generateTagPages,
generateRedirectPages
} = require('./gatsby/createPages')
2018-09-30 03:11:08 +02:00
const { itemsPerPage } = require('./config')
2018-09-06 22:28:28 +02:00
2018-07-17 23:33:55 +02:00
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
2018-09-13 00:46:40 +02:00
// Markdown files
2018-07-17 23:33:55 +02:00
if (node.internal.type === 'MarkdownRemark') {
2018-10-14 02:25:24 +02:00
createMarkdownFields(node, createNodeField, getNode)
2018-09-13 00:46:40 +02:00
}
// Image files
if (node.internal.mediaType === 'image/jpeg') {
2018-10-14 02:25:24 +02:00
createExifFields(node, createNodeField)
2018-09-12 21:03:35 +02:00
}
2018-09-09 21:20:19 +02:00
}
2019-01-04 18:51:03 +01:00
exports.createPages = async ({ graphql, actions }) => {
2018-09-24 23:50:48 +02:00
const { createPage, createRedirect } = actions
2018-07-17 23:33:55 +02:00
2019-01-04 18:51:03 +01:00
const result = await graphql(`
{
2019-02-03 21:18:59 +01:00
allMarkdownRemark {
2019-01-04 18:51:03 +01:00
edges {
node {
fields {
slug
}
frontmatter {
tags
2018-07-17 23:33:55 +02:00
}
}
}
2019-01-04 18:51:03 +01:00
}
}
`)
2018-07-17 23:33:55 +02:00
2019-01-04 18:51:03 +01:00
if (result.errors) throw result.errors
2018-07-19 00:22:06 +02:00
2019-01-04 18:51:03 +01:00
const posts = result.data.allMarkdownRemark.edges
const numPages = Math.ceil(posts.length / itemsPerPage)
2018-07-19 23:04:41 +02:00
2019-01-04 18:51:03 +01:00
// Generate posts & posts index
generatePostPages(createPage, posts, numPages)
2018-07-19 23:04:41 +02:00
2019-01-04 18:51:03 +01:00
// Generate Tag Pages
generateTagPages(createPage, posts, numPages)
2018-09-24 23:50:48 +02:00
2019-01-04 18:51:03 +01:00
// create manual redirects
generateRedirectPages(createRedirect)
2018-07-17 23:33:55 +02:00
}
2019-01-08 21:59:55 +01:00
// Fix web3
// https://github.com/ethereum/web3.js/issues/1105#issuecomment-446039296
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
// replace native `scrypt` module with pure js `js-scrypt`
scrypt: 'js-scrypt'
}
},
plugins: [
// ignore these plugins completely
new webpack.IgnorePlugin(/^(?:electron|ws)$/)
]
})
}