This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgatsby-node.js
53 lines (47 loc) · 1.52 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
const path = require(`path`)
const pageTemplate = path.resolve(`./src/templates/page.js`)
const postTemplate = path.resolve(`./src/templates/post.js`)
const contentfulQuery = contentType => `
{
content: allContentful${contentType} {
nodes {
slug
}
}
}
`
const pageSets = [
[contentfulQuery(`Page`), pageTemplate],
[contentfulQuery(`Post`), postTemplate],
]
exports.createPages = async ({ graphql, actions }) => {
await Promise.all(
pageSets.map(async ([query, component]) => {
const response = await graphql(query)
if (response.errors) throw new Error(response.errors)
response.data.content.nodes.forEach(({ slug }) => {
// exclude pages defined in src/pages
if (![`/`, `/standorte`].includes(slug)) {
actions.createPage({ path: slug, component, context: { slug } })
}
})
})
)
}
exports.onCreateNode = ({ node }) => {
// Ensure all slugs start with a forward slash.
if (node.slug && !node.slug.startsWith(`/`)) node.slug = `/` + node.slug
// Prefix all post slugs with /blog.
if (node.internal.type === `ContentfulPost`) node.slug = `/blog` + node.slug
if (node.internal.type === `ContentfulChapter`)
node.slug = `/standorte` + node.slug
}
// Enable absolute imports from `src`.
// See https://gatsbyjs.org/docs/add-custom-webpack-config#absolute-imports.
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, `src`), `node_modules`],
},
})
}