-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
190 lines (167 loc) · 4.5 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const each = require('lodash/each')
const Promise = require('bluebird')
const path = require('path')
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
* Found here https://github.com/sayjeyhi/snakeAndLadders/blob/master/gatsby-node.js
* and closed with this reco: https://github.com/gatsbyjs/gatsby/issues/17661
*/
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions
}) => {
actions.setWebpackConfig({
resolve: {
alias: {
'~components': path.resolve(__dirname, 'src/components'),
'~images': path.resolve(__dirname, 'src/images'),
'~hooks': path.resolve(__dirname, 'src/lib/hooks')
},
}
});
if (stage === "develop-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /canvas/,
use: loaders.null(),
},
],
},
})
}
};
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const indexPage = path.resolve('./src/pages/index.js')
// const recipePage = path.resolve('./src/pages/index.js')
// Apparently, it will create index by default as well
// as anything in src/pages/* as static pages
const topicArticles = path.resolve('./src/templates/topic-articles.js')
await graphql(`
query FindAllLabels {
whealthy {
getObjects(bucket_slug: "payonk-jama", input: {type: "labels"}) {
objects {
slug
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
const topics = result.data.whealthy.getObjects.objects;
each(topics, (topic) => {
createPage({
path: `topics/${topic.slug}`,
component: topicArticles,
context: {
slug: topic.slug,
},
})
})
})
const postRoot = 'blog';
// createPage({
// path: postRoot,
// component: indexPage,
// })
const blogPost = path.resolve('./src/templates/blog-post.js')
await graphql(
`
{
allCosmicjsPosts(sort: { fields: [created], order: DESC }, limit: 1000) {
edges {
node {
slug,
title
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
console.log("Got here----");
// Create blog posts pages.
const posts = result.data.allCosmicjsPosts.edges;
each(posts, (post, index) => {
const next = index === posts.length - 1 ? null : posts[index + 1].node;
const previous = index === 0 ? null : posts[index - 1].node;
createPage({
path: `${postRoot}/${post.node.slug}`,
component: blogPost,
context: {
slug: post.node.slug,
previous,
next,
},
})
})
});
return new Promise((resolve, reject) => {
const recipePost = path.resolve('./src/templates/recipe-post.js')
resolve(
graphql(
`
{
allCosmicjsRecipes(sort: { fields: [created], order: DESC }, limit: 1000) {
edges {
node {
slug,
title
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
// Create recipes posts pages.
const recipes = result.data.allCosmicjsRecipes.edges;
each(recipes, (recipe, index) => {
const next = index === recipes.length - 1 ? null : recipes[index + 1].node;
const previous = index === 0 ? null : recipes[index - 1].node;
createPage({
path: `recipes/${recipe.node.slug}`,
component: recipePost,
context: {
slug: recipe.node.slug,
previous,
next,
},
})
})
})
)
})
}
// Implement the Gatsby API “onCreatePage”. This is
// called after every page is created.
exports.onCreatePage = async ({ page, actions }) => {
const { createPage } = actions
// Only update the `/app` page.
if (page.path.match(/^\/app/)) {
// page.matchPath is a special key that's used for matching pages
// with corresponding routes only on the client.
page.matchPath = "/app/*"
// Update the page.
createPage(page)
}
}