-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
95 lines (87 loc) · 2.02 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
// https://www.gatsbyjs.com/plugins/gatsby-source-drupal/
// IF using Gatsby IN a Docker container
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
watchOptions: {
aggregateTimeout: 200,
poll: 1000,
ignored: "**/node_modules",
},
})
}
const handlePath = (pathInput, nid) => {
if (pathInput != null) {
return pathInput
} else if (pathInput === "/home") {
return "/"
} else if (pathInput === "/404") {
return "/404"
} else if (pathInput === "/403") {
return "/403"
} else {
return `/node/${nid}`
}
}
//https://www.gatsbyjs.com/docs/programmatically-create-pages-from-data/
exports.createPages = async function ({ actions, graphql }) {
const { data } = await graphql(`
query {
pages: allDrupalNodePage(limit: 100) {
edges {
node {
drupal_internal__nid
id
title
path {
alias
}
}
}
}
articles: allDrupalNodeArticle(limit: 100) {
edges {
node {
id
title
path {
alias
}
drupal_internal__nid
}
}
}
}
`)
// Use a template to build out all Node type 'Pages'.
data.pages.edges.forEach((edge) => {
const slug = handlePath(
edge.node.path.alias,
edge.node.drupal_internal__nid
)
const id = edge.node.id
actions.createPage({
path: slug,
component: require.resolve(`./src/templates/nodepage.js`),
context: {
slug: slug,
id: id,
},
})
})
// Use a template to build out all Node type 'Pages'.
data.articles.edges.forEach((edge) => {
const slug = handlePath(
edge.node.path.alias,
edge.node.drupal_internal__nid
)
const id = edge.node.id
actions.createPage({
path: slug,
component: require.resolve(`./src/templates/nodearticle.js`),
context: {
slug: slug,
id: id,
},
})
})
}