forked from binary-com/deriv-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
73 lines (64 loc) · 2.76 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
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)
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
// TODO: this is a temporary workaround to remove a/b testing page
const homepage_regex = /homepage/g
// TODO: this is a temporary workaround to remove a/b testing page
const amp_regex = /amp/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) ||
homepage_regex.test(localized_path) ||
amp_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 })
}
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'],
},
})
}