This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgatsby-node.js
46 lines (41 loc) · 1.66 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
const path = require('path')
const language_config = require(`./src/components/localization/language-config.js`)
const translations_cache = {}
// Based upon https://github.com/gatsbyjs/gatsby/tree/master/examples/using-i18n
exports.onCreatePage = ({ page, actions }) => {
const { 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}`
if (!translations_cache[lang]) {
const translation_json = require(`./src/translations/${lang}`)
translations_cache[lang] = translation_json
}
return 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,
},
})
})
}
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'],
},
})
}