You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ozgurkon-2020-site/tools/extract-data.js

39 lines
890 B

6 years ago
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');
6 years ago
const writeOption = {
flag: 'w'
6 years ago
};
6 years ago
const writeToYml = (list, dest) => {
const data = yaml.safeDump(list);
6 years ago
console.log('Write to', dest);
6 years ago
fs.writeFileSync(dest, data, writeOption);
6 years ago
};
const firebaseData = require('../test-hugo/data/firebase-data.json');
6 years ago
const identity = obj => obj;
6 years ago
const idValue = obj =>
Object.entries(obj)
6 years ago
.map(([key, elt]) => ({
...elt,
id: key
}));
6 years ago
const dataExtractor = {
sessions: idValue,
speakers: idValue,
partners: identity,
team: identity,
tickets: identity,
6 years ago
};
6 years ago
Object.entries(dataExtractor)
.forEach(([key, value]) => {
6 years ago
const dest = path.join(__dirname, `../test-hugo/data/${key}.yml`);
const data = value(firebaseData[key]);
writeToYml(data, dest);
});