-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridsome.server.js
80 lines (61 loc) · 1.92 KB
/
gridsome.server.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
const cantons = require('./src/data/cantons');
const allHolidays = require('./src/data/holidays/allHolidays');
const globalConfig = require('./src/config/global');
const addCantonsCollection = (actions) => {
const cantonsCollection = actions.addCollection('Canton');
const {
years
} = globalConfig;
for (const canton of cantons) {
let holidays = [];
let holidaysCount = 0;
for (const year of years) {
const holidaysForYear = allHolidays.getHolidaysForYearAndCanton(year, canton.key);
if (holidaysCount === 0) {
holidaysCount = holidaysForYear.length;
}
const extractCantonInfo = holidaysForYear.map((holiday) => {
const cantonInfo = holiday.cantons[canton.key];
const _holiday = JSON.parse(JSON.stringify(holiday));
_holiday.allCanton = cantonInfo.allCanton;
_holiday.official = cantonInfo.official;
_holiday.half = cantonInfo.half;
_holiday.memo = cantonInfo.memo;
return _holiday;
});
holidays = holidays.concat(extractCantonInfo);
}
cantonsCollection.addNode({
holidays,
holidaysCount,
id: canton.key,
...canton
});
}
};
const addHolidaysCollection = (actions) => {
const holidaysCollection = actions.addCollection('Holiday');
let holidays = [];
const {
years
} = globalConfig;
for (const year of years) {
const holidaysForYear = allHolidays.getHolidaysForYear(year);
const extractCantonInfo = holidaysForYear.map((holiday) => {
const _holiday = JSON.parse(JSON.stringify(holiday));
const cantonKeys = Object.keys(_holiday.cantons);
_holiday.cantons = cantonKeys;
return _holiday;
});
holidays = holidays.concat(extractCantonInfo);
}
holidaysCollection.addNode({
holidays
});
};
module.exports = (api) => {
api.loadSource((actions) => {
addCantonsCollection(actions);
addHolidaysCollection(actions);
});
};