summaryrefslogtreecommitdiff
path: root/ICal.ts
diff options
context:
space:
mode:
authorTim Schiewe <git@tforge.de>2018-04-30 17:58:35 +0200
committerTim Schiewe <git@tforge.de>2018-04-30 17:58:35 +0200
commit588c0fee4a47efe71b5bae37676228ae563295d9 (patch)
treec4324a657d9db5aae691202f88a94c76593dd25a /ICal.ts
parenta439d29d8ff0bbee2d7c92c7594729c13c87baf8 (diff)
parent96d612b65b9fb6caccb2bf6fc45c8a409f521b02 (diff)
downloadsplus-588c0fee4a47efe71b5bae37676228ae563295d9.tar.gz
splus-588c0fee4a47efe71b5bae37676228ae563295d9.zip
Merge branch 'feature/1-ics'
Diffstat (limited to 'ICal.ts')
-rw-r--r--ICal.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/ICal.ts b/ICal.ts
new file mode 100644
index 0000000..fe74dab
--- /dev/null
+++ b/ICal.ts
@@ -0,0 +1,30 @@
+// ref. https://www.npmjs.com/package/ical-generator
+import * as ical from 'ical-generator';
+import * as crypto from 'crypto';
+import * as fs from 'fs';
+
+const TARGET_FILE = 'docs/informatik1.ics';
+const DOMAIN = 'schneefux.github.io'; // TODO config management
+
+const sha256 = (x) => crypto.createHash('sha256').update(x, 'utf8').digest('hex');
+
+const cal = ical();
+
+// TODO declare an interface
+export function createEvent(event) {
+ // TODO better duplicate detection and resolve conflicts lol
+ const eventId = sha256(JSON.stringify(event)).substr(0, 16);
+
+ const icalEvent = cal.createEvent({
+ uid: eventId,
+ start: event.start.dateTime,
+ end: event.end.dateTime,
+ timestamp: new Date(),
+ summary: event.summary,
+ description: event.description,
+ });
+}
+
+export function commit() {
+ fs.writeFile(TARGET_FILE, cal.toString(), (err) => {});
+}