-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.js
46 lines (41 loc) · 1.36 KB
/
events.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
/** @format */
const fs = require("fs");
const readline = require("readline");
let activities = [];
let currentActivity = null;
const rl = readline.createInterface({
input: fs.createReadStream("events.md"),
output: process.stdout,
terminal: false,
});
rl.on("line", line => {
if (line.startsWith("#")) {
currentActivity = {
title: line.substring(1).trim(),
subtitle: "",
description: "",
date: "",
location: "",
price: "",
link: "",
image: "",
};
activities.push(currentActivity);
} else if (line.startsWith("*")) {
const value = line.substring(1).trim();
if (!currentActivity.subtitle) currentActivity.subtitle = value;
else if (!currentActivity.description)
currentActivity.description = value;
else if (!currentActivity.date) currentActivity.date = value;
else if (!currentActivity.location) currentActivity.location = value;
else if (!currentActivity.price) currentActivity.price = value;
else if (!currentActivity.link) currentActivity.link = value;
else if (!currentActivity.image) currentActivity.image = value;
}
});
rl.on("close", () => {
fs.writeFileSync(
"events.json",
JSON.stringify({ activities: activities }, null, 2)
);
});