forked from ActiveCampaign/smtp-field-manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
125 lines (109 loc) · 3.44 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
const queries = require('./src/utils/queries')
const _ = require('lodash')
const helpers = require('./src/utils/helpers')
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
exports.createPages = async ({ graphql, actions }) => {
const { createPage, createRedirect } = actions
// Create response code pages
const codes = await graphql(queries.codes)
codesFlat = helpers.flatten(codes.data.allCodesJson)
codesFlat.forEach(item => {
const data = {
...item,
otherCodes: _.reject(codesFlat, { reply: item.reply }),
}
createPage({
path: `/code${item.slug}`,
component: require.resolve(`./src/templates/code.js`),
context: { data },
})
})
// Create provider pages
const providers = await graphql(queries.emailProviders)
providersFlat = helpers.flatten(providers.data.allEmailProvidersJson)
providersFlat.forEach(item => {
let data = {
...item,
codes: [],
otherProviders: _.reject(providersFlat, { id: item.id }),
}
// Gather codes for this provider
codesFlat.map(code => {
code.providers.map(provider => {
if (provider.id === data.id) {
data.codes.push({
description: code.description,
reply: code.reply,
responses: provider.responses,
})
provider.responses.map(response => {
const responsePageData = {
response: response,
code: code,
provider: provider,
type: 'provider'
}
createPage({
path: `/provider${data.slug}/${code.reply}/${response.status}`,
component: require.resolve(`./src/templates/response.js`),
context: { responsePageData },
})
})
}
})
})
createPage({
path: `/provider${data.slug}`,
component: require.resolve(`./src/templates/provider.js`),
context: { data },
})
})
// Create spam filter pages
const spamFilters = await graphql(queries.spamFilters)
spamFiltersFlat = helpers.flatten(spamFilters.data.allSpamFiltersJson)
spamFiltersFlat.forEach(item => {
let data = {
...item,
codes: [],
otherProviders: _.reject(spamFiltersFlat, { id: item.id }),
}
// Gather codes for this provider
codesFlat.map(code => {
code.spamFilters.map(provider => {
if (provider.id === data.id) {
data.codes.push({
description: code.description,
reply: code.reply,
responses: provider.responses,
})
provider.responses.map(response => {
const responsePageData = {
response: response,
code: code,
provider: provider,
type: 'spamfilter'
}
createPage({
path: `/spamfilter${data.slug}/${code.reply}/${response.status}`,
component: require.resolve(`./src/templates/response.js`),
context: { responsePageData },
})
})
}
})
})
createPage({
path: `/spamfilter${data.slug}`,
component: require.resolve(`./src/templates/spamFilter.js`),
context: { data },
})
})
// Create redirects
const redirects = await graphql(queries.redirects)
const redirectsFlat = helpers.flatten(redirects.data.allRedirectsJson)
redirectsFlat.forEach(item => createRedirect(item))
}