summaryrefslogtreecommitdiff
path: root/src/ICal.ts
blob: 09bc9bfa7dfde553eb38394c32414dfe51e6934b (plain)
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
// 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) => {});
}