-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
61 lines (55 loc) · 1.37 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
const path = require("path")
const organizedByCategory = allData => {
const organized = {}
for (const { node: data } of allData) {
if (organized[data.category]) organized[data.category].push(data)
else organized[data.category] = [data]
}
return Object.entries(organized)
}
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions
const newsPageTemplate = path.resolve("src/templates/news-pages.js")
return graphql(`
{
allMongodbProdPosts {
edges {
node {
id
author
category
path
image
link
messageID
channelID
title
stream
news {
path
author
category
image
link
title
}
}
}
}
}
`).then(res => {
if (res.errors) return Promise.reject(res.errors)
const organizedData = organizedByCategory(
res.data.allMongodbProdPosts.edges
)
// console.log('where does this log', res.data.allMongodbProdPosts.edges)
for (const data of organizedData) {
if (data[0] && data[0].toLowerCase() === 'entertainment') continue;
createPage({
path: data[0],
component: newsPageTemplate,
context: data[1],
})
}
})
}