-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
55 lines (50 loc) · 1.51 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
import { createFilePath } from "gatsby-source-filesystem"
// https://www.gatsbyjs.org/docs/node-apis/#onCreateWebpackConfig
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
// https://www.gatsbyjs.org/docs/debugging-html-builds/#fixing-third-party-modules
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /scrollreveal/,
use: loaders.null(),
},
],
},
})
}
}
exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions
const { language } = page.context.intl
deletePage(page)
createPage({
...page,
context: {
...page.context,
language,
},
})
}
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (
node.internal.type === `DataYaml` ||
node.internal.type === `MarkdownRemark`
) {
const path = createFilePath({ node, getNode })
const langCode = extractLanguageCode(path)
createNodeField({
name: `language`,
node,
value: langCode,
})
}
function extractLanguageCode(path) {
const length = path.length
const start = length - 3
const end = start + 2
return path.substring(start, end)
}
}