-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
127 lines (120 loc) · 3.22 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
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
exports.createPages = async function ({ actions, graphql }) {
const props = await graphql(`
query prismicData {
allPrismicConfiguration(
sort: { fields: last_publication_date, order: ASC }
) {
nodes {
lang
id
type
dataRaw
}
}
allPrismicContacts(sort: { fields: last_publication_date, order: ASC }) {
nodes {
type
lang
id
dataRaw
}
}
allPrismicPackage(sort: { fields: last_publication_date, order: ASC }) {
nodes {
type
lang
dataRaw
id
}
}
allPrismicPartners(sort: { fields: last_publication_date, order: ASC }) {
nodes {
dataRaw
id
lang
type
}
}
allPrismicPortfolio(sort: { fields: last_publication_date, order: ASC }) {
nodes {
dataRaw
id
lang
type
}
}
allPrismicService(sort: { fields: last_publication_date, order: ASC }) {
nodes {
dataRaw
id
lang
type
}
}
}
`);
const Models = require("./src/models/AppModels.js");
/** @type {Models.PageMisc[]}*/
const configsData = props.data.allPrismicConfiguration.nodes.map((e) =>
Models.PageMisc.fromPrismic(e)
);
/** @type {Models.Contacts[]}*/
const contactsData = props.data.allPrismicContacts.nodes.map((e) =>
Models.Contacts.fromPrismic(e)
);
/** @type {Models.PackageItem[]}*/
const packagesData = props.data.allPrismicPackage.nodes.map((e) =>
Models.PackageItem.fromPrismic(e)
);
/** @type {Models.Partners[]}*/
const partnersData = props.data.allPrismicPartners.nodes.map((e) =>
Models.Partners.fromPrismic(e)
);
/** @type {Models.PortfolioItem[]}*/
const portfoliosData = props.data.allPrismicPortfolio.nodes.map((e) =>
Models.PortfolioItem.fromPrismic(e)
);
/** @type {Models.Service[]}*/
const servicesData = props.data.allPrismicService.nodes.map((e) =>
Models.Service.fromPrismic(e)
);
/**
* @template T[]
* @param {T[]} a
* @param {String} l
* @returns {T[]}
*/
const filterLang = (a, l) => {
const result = [];
for (var i = 0; i < a.length; i++) {
const e = a[i];
if (Array.isArray(e)) {
const sub = filterLang(e, l);
if (sub.length != 0) result.push(sub);
} else if (e.lang == l) result.push(e);
}
return result;
};
const languages = configsData.map((e) => e.lang);
languages.map((locale) => {
actions.createPage({
path: `/${locale}`,
component: require.resolve(`./src/templates/LocalizedIndex.js`),
context: {
locale: locale,
languages: languages,
packages: filterLang(packagesData, locale),
portfolios: filterLang(portfoliosData, locale),
services: filterLang(servicesData, locale),
config: filterLang(configsData, locale)[0],
partners: filterLang(partnersData, locale)[0],
contacts: filterLang(contactsData, locale)[0],
},
});
});
actions.createPage({
path: "/",
component: require.resolve("./src/templates/index.js"),
context: {},
});
};