-
Notifications
You must be signed in to change notification settings - Fork 3
/
toReadme.js
98 lines (85 loc) · 3.36 KB
/
toReadme.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
const fs = require('fs');
const path = require('path');
const main = async () => {
try {
const dataAsString = await fs.readFileSync(path.resolve(`./data/events.json`), { encoding: 'utf-8' });
const dataAsJson = JSON.parse(dataAsString);
var readmeHeader = "# Developer Circle Jakarta - Public Data\n";
readmeHeader += "\n![Generate README](https://github.com/devcjakarta/Public-Data/workflows/Generate%20README/badge.svg)\n";
readmeHeader += "\nDeveloper Circle Jakarta - Public Data\n";
var readmeContent = "\n";
var tableOfContents = "\n## Daftar Event 2020\n"
tableOfContents += "\nsee [events.json](data/events.json)\n";
var count = dataAsJson.data.length;
var lastEvent = "";
var indexEvent = 1;
var link = "";
dataAsJson.data.forEach(event => {
link = doDashes(event.name);
tableOfContents += "\n- [" + event.name + "](#"+link+")"; //todo: add hyperlink
if ((indexEvent==1)&&(event.banner !== undefined)){
lastEvent = "\n## Last Event";
lastEvent += "\n\n![Last Event](files/image/" + event.banner + ")\n";
//console.log(lastEvent);process.exit();
}
readmeContent += "\n### " + event.name + "\n";
readmeContent += "\n- Tanggal: " + event.date;
if (event.time != ""){
readmeContent += "\n- Pukul: " + event.time;
}
if (Array.isArray(event.speaker)){
readmeContent += "\n- Pembicara: ";
event.speaker.forEach(item => {
readmeContent += "\n - " + item.name;
if (item.title != ""){
readmeContent += ", " + item.title;
}
});
}else{
if (event.speaker.name != ""){
readmeContent += "\n- Pembicara: " + event.speaker.name;
if (event.speaker.title != ""){
readmeContent += ", " + event.speaker.title;
}
}
}
if (event.url != ""){
readmeContent += "\n- " + event.url;
}
if (event.others !== undefined){
const others = event.others;
for (var item in others) {
key = item.replace("_url", "");
key = key.replace("_", " ");
value = others[item];
if (value !== ""){
readmeContent += "\n- [" + key + '](' + value + ')';
}
}
}
readmeContent += "\n";
indexEvent++;
});
readmeContent += "\n";
var readmeFooter = "\n## Bantu kami\n";
readmeFooter += "\nBantu kami memperbarui daftar ini 🙏\n";
readmeFooter += "\nPantau grup [Facebook Developer Circle Jakarta](https://www.facebook.com/groups/devcjakarta) dan silahkan perbarui data setiap kali ada sesi baru.\n";
readmeFooter += "\nKami sangat berterima kasih untuk setiap bantuan yang teman-teman berikan.\n";
readmeFooter += "\n----\n";
readmeFooter += "\n©️ 2020 by DevC Jakarta Team";
readmeContent = readmeHeader + lastEvent + tableOfContents + readmeContent + readmeFooter;
console.log(readmeContent);
fs.writeFile(path.resolve('./README.md'), readmeContent, function (err){
if (err){
return console.log('❌ Error write file README.md', err);
}
console.log('✅ Success write file README.md');
});
} catch (error) {
console.error('❌ Error read file events.json', error);
}
}
function doDashes(str) {
return str.replace(/[^a-z0-9]+/gi, '-').replace(/^-*|-*$/g, '').toLowerCase();
}
main();