-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
95 lines (83 loc) · 2.2 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
const path = require(`path`)
const { slash } = require(`gatsby-core-utils`)
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
// query content for WordPress posts
const {
data: {
allWpPage: { nodes: allPages },
allWpProject: { nodes: allProjects }
},
} = await graphql(`
query {
allWpPage {
nodes {
id
uri
language {
code
}
translations {
uri
}
}
}
allWpProject {
nodes {
id
uri
language {
code
}
translations {
uri
}
}
}
}
`)
const pageTemplate = path.resolve(`./src/templates/page/index.js`)
const projectTemplate = path.resolve(`./src/templates/project/index.js`)
allPages.forEach(page => {
const prefix = page.language.code === "DE" ? "/de" : ""
let translation = undefined
if (page.translations.length > 0) {
translation = page.translations[0].uri
if (page.language.code === "EN") {
translation = "/de" + translation
}
}
createPage({
path: prefix + page.uri,
component: slash(pageTemplate),
// In the ^template's GraphQL query, 'id' will be available
// as a GraphQL variable to query for this post's data.
context: {
id: page.id,
translation: translation,
language: page.language.code === "DE" ? "de" : "en"
},
})
})
allProjects.forEach(project => {
const prefix = project.language.code === "DE" ? "/de" : ""
let translation = undefined
if (project.translations.length > 0) {
translation = project.translations[0].uri
if (project.language.code === "EN") {
translation = "/de" + translation
}
}
createPage({
path: prefix + project.uri,
component: slash(projectTemplate),
// In the ^template's GraphQL query, 'id' will be available
// as a GraphQL variable to query for this post's data.
context: {
id: project.id,
translation: translation,
language: project.language.code === "DE" ? "de" : "en"
},
})
})
}