From 93b466df50d94d4c15715f5eb4d88a0be7d61c11 Mon Sep 17 00:00:00 2001 From: Tim Schiewe Date: Mon, 30 Apr 2018 18:15:52 +0200 Subject: Create better structure --- src/ICal.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/ICal.ts (limited to 'src/ICal.ts') diff --git a/src/ICal.ts b/src/ICal.ts new file mode 100644 index 0000000..09bc9bf --- /dev/null +++ b/src/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 = 'etc/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) => {}); +} -- cgit v1.3.1