-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-prrender-urls.js
55 lines (44 loc) · 1.5 KB
/
compile-prrender-urls.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
require('isomorphic-fetch');
const fs = require('fs');
//const utils = require('./src/components/utils.js');
const states = [
{ "name": "Burgenland", "stateNumber": 1 },
{ "name": "Kärnten", "stateNumber": 2 },
{ "name": "Niederösterreich", "stateNumber": 3 },
{ "name": "Oberösterreich", "stateNumber": 4 },
{ "name": "Salzburg", "stateNumber": 5 },
{ "name": "Steiermark", "stateNumber": 6 },
{ "name": "Tirol", "stateNumber": 7 },
{ "name": "Vorarlberg", "stateNumber": 8 },
{ "name": "Wien", "stateNumber": 9 }
];
const getStateName = function(stateNumber) {
const state = states.filter(state => state.stateNumber === stateNumber)[0];
if (state) {
return state.name;
}
};
function urlencode(url) {
return url.replace(/ /g, "_");
}
const fetches = [];
for(let i = 1; i <= 9; i++) {
fetches[i-1] = fetch('https://geocode.at/autocomplete?state=' + i).then(function(response) {
return response.json();
});
}
Promise.all(fetches).then(function(jsons) {
jsons.map((j) => console.log(j));
jsons = jsons.map((j, i) => j.map((a) => ({
"url": "/game/" + getStateName(i+1)+ "/" + urlencode(a),
"title": "Wie gut kennst Du Dich in " + a + " aus? - GeoTraining.at"
})));
let json = [];
jsons.map((j) => json = json.concat(j));
fs.writeFile("out.json", JSON.stringify(json), function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
});