-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
51 lines (43 loc) · 1.12 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
const path = require("path")
const _ = require("lodash")
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const keywordTemplate = path.resolve("src/templates/keywords.js")
const result = await graphql(`{
keywordsGroup: allMdx(limit: 2000) {
group(field: {frontmatter: {keywords: SELECT}}) {
fieldValue
}
}
}`)
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
const keywords = result.data.keywordsGroup.group
keywords.forEach(keyword => {
createPage({
path: `/keywords/${_.kebabCase(keyword.fieldValue)}/`,
component: keywordTemplate,
context: {
keyword: keyword.fieldValue,
},
})
})
}
exports.createSchemaCustomization = ({ actions }) => {
actions.createTypes(`
type SitePage implements Node @dontInfer {
path: String!
}
`)
}
exports.onCreateWebpackConfig = ({ actions, stage, getConfig }) => {
if (stage === `develop` || stage === `develop-html`) {
actions.setWebpackConfig({
cache: {
compression: "gzip",
},
})
}
}