This repository has been archived by the owner on Oct 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgatsby-node.js
69 lines (62 loc) · 1.72 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
const Promise = require('bluebird')
const path = require('path')
const select = require(`unist-util-select`)
const precache = require(`sw-precache`)
const fs = require(`fs-extra`)
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const webpack = require('webpack')
exports.createPages = ({ graphql, boundActionCreators: { createPage } }) => {
return new Promise((resolve, reject) => {
const page = path.resolve('src/templates/page.js')
graphql(`
query PageQuery {
allMarkdownRemark(limit: 1000) {
edges {
node {
fields { slug }
}
}
}
}
`)
.then(result => {
if (result.errors) {
return reject(result.errors)
}
result.data.allMarkdownRemark.edges.map(edge => (
{
path: edge.node.fields.slug, // required
component: page,
context: {
slug: edge.node.fields.slug,
},
}
)).forEach(page => createPage(page))
resolve()
})
})
}
// Add custom url pathname for pages
exports.onCreateNode = ({ node, boundActionCreators: { createNodeField }, getNode }) => {
if (node.internal.type === `File`) {
createNodeField({
node,
fieldName: "slug",
fieldValue: `/${path.dirname(node.relativePath)}/`
})
} else if (node.internal.type === `MarkdownRemark`) {
createNodeField({
node,
fieldName: "slug",
fieldValue: node.frontmatter.path || getNode(node.parent).fields.slug
})
}
}
exports.modifyWebpackConfig = ({ config, stage }) => {
config.plugin('webpack-provide', webpack.ProvidePlugin, [{
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}])
return config
}