-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
246 lines (227 loc) · 7.48 KB
/
gatsby-node.js
File metadata and controls
246 lines (227 loc) · 7.48 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
const language_config = require(`./i18n-config.js`)
const path = require('path')
const translations_cache = {}
// Based upon https://github.com/gatsbyjs/gatsby/tree/master/examples/using-i18n
exports.onCreatePage = ({ page, actions }) => {
const { createRedirect, createPage, deletePage } = actions
// First delete the incoming page that was automatically created by Gatsby
// So everything in src/pages/
deletePage(page)
const is_responsible_trading = /responsible/g.test(page.path)
const is_contact_us = /contact_us/g.test(page.path)
const is_p2p = /responsible/g.test(page.path)
const is_story = /story/g.test(page.path)
const is_market = /markets/g.test(page.path)
if (is_responsible_trading) {
createRedirect({
fromPath: `/responsible-trading/`,
toPath: `/responsible/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/responsible-trading`,
toPath: `/responsible`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_contact_us) {
createRedirect({
fromPath: `/contact-us/`,
toPath: `/contact_us/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/contact/`,
toPath: `/contact_us/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/contact-us`,
toPath: `/contact_us`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_p2p) {
createRedirect({
fromPath: `/p2p/v1`,
toPath: `/p2p`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/p2p/v2`,
toPath: `/p2p`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_story) {
createRedirect({
fromPath: `/about/`,
toPath: `/story/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/about`,
toPath: `/story/`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_market) {
createRedirect({
fromPath: `/markets/`,
toPath: `/markets/forex/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/markets`,
toPath: `/markets/forex/`,
redirectInBrowser: true,
isPermanent: true,
})
}
Object.keys(language_config).map((lang) => {
// Use the values defined in "locales" to construct the path
const { path, is_default } = language_config[lang]
const localized_path = is_default ? page.path : `${path}${page.path}`
const is_production = process.env.GATSBY_ENV === 'production'
const careers_regex = /^[a-z-]+\/careers\//g
const endpoint_regex = /^[a-z-]+\/endpoint\//g
const offline_plugin_regex = /^[a-z-]+\/offline-plugin-app-shell-fallback/g
if (is_production) {
if (path === 'ach') return
}
if (
careers_regex.test(localized_path) ||
endpoint_regex.test(localized_path) ||
offline_plugin_regex.test(localized_path)
)
return
if (!translations_cache[lang]) {
const translation_json = require(`./src/translations/${lang}`)
translations_cache[lang] = translation_json
}
const current_page = createPage({
// Pass on everything from the original page
...page,
// Remove trailing slash from page.path (e.g. "/de/")
path: localized_path,
// Pass in the locale as context to every page
context: {
...page.context,
locale: lang,
localeResources: translations_cache[lang],
pathname: localized_path,
},
})
if (is_default) {
const en_path = `/en${localized_path.slice(0, -1)}`
createRedirect({
fromPath: en_path,
toPath: localized_path,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `${en_path}/`,
toPath: localized_path,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_responsible_trading) {
createRedirect({
fromPath: `/${lang}/responsible-trading/`,
toPath: `/${lang}/responsible/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/responsible-trading`,
toPath: `/${lang}/responsible`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_contact_us) {
createRedirect({
fromPath: `/${lang}/contact-us/`,
toPath: `/${lang}/contact_us/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/contact/`,
toPath: `/${lang}/contact_us/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/contact-us`,
toPath: `/${lang}/contact_us`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_p2p) {
createRedirect({
fromPath: `/${lang}/p2p/v1`,
toPath: `/${lang}/p2p`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/p2p/v2`,
toPath: `/${lang}/p2p`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_story) {
createRedirect({
fromPath: `/${lang}/about/`,
toPath: `/${lang}/story/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/about`,
toPath: `/${lang}/story/`,
redirectInBrowser: true,
isPermanent: true,
})
}
if (is_market) {
createRedirect({
fromPath: `/${lang}/markets/`,
toPath: `/${lang}/markets/forex/`,
redirectInBrowser: true,
isPermanent: true,
})
createRedirect({
fromPath: `/${lang}/markets`,
toPath: `/${lang}/markets/forex/`,
redirectInBrowser: true,
isPermanent: true,
})
}
return current_page
})
}
exports.onCreateWebpackConfig = ({ actions, getConfig }) => {
const config = getConfig()
if (config.optimization) config.optimization.minimizer[0].options.parallel = 2
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
})
}