-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridsome.server.js
56 lines (46 loc) · 1.95 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
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api/
// Changes here require a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const axios = require('axios');
const getArmSales = async (api) => {
const GOOGLE_SHEETS_URL_ARMS = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vR-i79q8iPpGMnvpusrGRcIF4MHOuwfEIlu1DjfptMvz1qIRMP050hrN3zW0KOQmO-oNxdpZLtGxUvc/pub?output=csv';
const GOOGLE_SHEETS_URL_COUNTRIES = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vSEtLTlhrqaW4nWz7M6p7UZObrfn_856Ht0qjPPmS-wKlGsbLk2Qqh8etvhlecDKV_2dywIW2y3oLsG/pub?output=csv';
const GSON = 'https://gson.fayazara.now.sh/?url=';
api.loadSource(async ({ addCollection }) => {
const { data } = await axios(`${GSON}${GOOGLE_SHEETS_URL_ARMS}`);
const countryData = await axios(`${GSON}${GOOGLE_SHEETS_URL_COUNTRIES}`);
const YEARS = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019];
const collection = addCollection('ArmSales');
const collectionYears = addCollection('ArmSalesYears');
data.reverse().forEach(el => {
collection.addNode({
'2010': el['2010'],
'2011': el['2011'],
'2012': el['2012'],
'2013': el['2013'],
'2014': el['2014'],
'2015': el['2015'],
'2016': el['2016'],
'2017': el['2017'],
'2018': el['2018'],
'2018': el['2018'],
'2019': el['2019'],
'2010-2019': el['2010-2019'],
data: el['2019'],
supplier: el.Supplier,
country: countryData.data.filter(x => x.name === el.Supplier)[0]
})
});
YEARS.forEach(el => {
collectionYears.addNode({ value: `_${el}` });
})
});
}
module.exports = function (api) {
getArmSales(api);
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api/
})
}