Repository navigation
Expand file tree
/
Copy pathgatsby-node.js
More file actions
86 lines (81 loc) · 2.15 KB
/
Copy pathgatsby-node.js
File metadata and controls
86 lines (81 loc) · 2.15 KB
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
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = ({ graphql, actions }) =>
graphql(`
{
docs: allMarkdownRemark(
limit: 1000
filter: { fileAbsolutePath: { regex: "/.*content/docs.*/" } }
sort: { order: DESC, fields: [frontmatter___date] }
) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
legal: allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/.*content/legal.*/" } }
) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
`).then(res => {
if (res.errors) throw res.errors
const docs = res.data.docs.edges
docs.forEach((post, index) => {
actions.createPage({
path: `docs${post.node.fields.slug}`,
component: path.resolve(`./src/templates/doc.tsx`),
context: {
slug: post.node.fields.slug,
previous: index === docs.length - 1 ? null : docs[index + 1].node,
next: index === 0 ? null : docs[index - 1].node
}
})
})
res.data.legal.edges.forEach((post, index) => {
actions.createPage({
path: `legal${post.node.fields.slug}`,
component: path.resolve(`./src/templates/legal.tsx`),
context: { slug: post.node.fields.slug }
})
})
return null
})
exports.onCreateNode = ({ node, actions: { createNodeField }, getNode }) => {
if (node.internal.type === `MarkdownRemark`) {
createNodeField({
name: `slug`,
node,
value: createFilePath({ node, getNode })
})
}
}
exports.onCreatePage = async ({ page, actions: { createPage } }) => {
if (page.path.match(/^\/app/)) {
page.matchPath = "/app/*"
createPage(page)
}
}
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: { rules: [{ test: /auth0-js/, use: loaders.null() }] }
})
}
}