-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
112 lines (106 loc) · 3.86 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const addSlugToNode = require('./src/generators/slugGenerator')
const generateEventPages = require('./src/generators/eventPageGenerator')
const generateGenericPages = require('./src/generators/genericPageGenerator')
const getMarkdownPages = require('./src/utils/getMarkdownPages')
const liquid = require('./src/utils/miniLiquid')
const partialRight = require('lodash.partialright')
// Keeps track of the first "featured" event
let FEATURED_NODE = null
function validateFeatures (node) {
if (node.frontmatter.feature) {
// If a Featured Event has already been defined, then throw.
// We cannot have *two* featured events!
if (FEATURED_NODE && FEATURED_NODE.id !== node.id) {
throw new Error(
`Multiple "featured" events detected: ${
FEATURED_NODE.frontmatter.date
} and ${node.frontmatter.date}`
)
}
FEATURED_NODE = node
}
return true
}
exports.onCreatePage = ({ page, boundActionCreators }) => {
const { createPage } = boundActionCreators
page.context = Object.assign({}, page.context, {
path: page.context.path || page.path
})
createPage(page)
return Promise.resolve()
}
exports.onCreateNode = ({ boundActionCreators, node, getNode }) => {
const { createNodeField } = boundActionCreators
if (node.internal.type === 'MarkdownRemark') {
validateFeatures(node)
addSlugToNode(createNodeField, getNode, node)
liquid(node)
}
}
exports.createPages = ({ boundActionCreators, graphql }) =>
getMarkdownPages(graphql)
.then(partialRight(generateEventPages, boundActionCreators))
.then(partialRight(generateGenericPages, boundActionCreators))
exports.modifyWebpackConfig = ({ config, stage, store }, options) => {
const { program } = store.getState()
switch (stage) {
case 'build-css':
// NOTE: Blow away the internal reference to the PostCSS config because the
// functional version of merge still doesn't replace it (even though the
// documentation of webpack-configurator says it should ¯\_(ツ)_/¯)
config._config.postcss = []
config.merge({
postcss: [
// NOTE: This disables PostCSS customProperties because the browsers
// support setting properties on non-root elements to allow overrides
// and PostCSS does not. Evergreen browsers have decently wide
// support for custom properties now, so there isn't as much need to
// "polyfill" them via PostCSS.
require(`postcss-import`)(),
require(`postcss-cssnext`)({
browsers: program.browserslist,
features: {
customMedia: {
extensions: {
'--phone': '(min-width: 640px)'
}
},
customProperties: false
}
}),
require(`postcss-extend`)
]
})
return config
case 'develop':
config.merge({
postcss (wp) {
// NOTE: This disables PostCSS customProperties because the browsers
// support setting properties on non-root elements to allow overrides
// and PostCSS does not. Evergreen browsers have decently wide
// support for custom properties now, so there isn't as much need to
// "polyfill" them via PostCSS.
return [
require(`postcss-import`)({ addDependencyTo: wp }),
require(`postcss-cssnext`)({
browsers: program.browserslist,
features: {
customMedia: {
extensions: {
'--phone': '(min-width: 640px)'
}
},
customProperties: false
}
}),
require(`postcss-extend`),
require(`postcss-browser-reporter`),
require(`postcss-reporter`)
]
}
})
return config
default:
return config
}
}