diff --git a/README.md b/README.md index 69622aa..ba4f4f3 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,6 @@ select summary, description ## Roadmap -- Decide which properties should be exposed: - - Location - - Color? - Add instructions for popular services: - Nextcloud - Google Calendar diff --git a/example-google.json b/example-google.json new file mode 100644 index 0000000..af84433 --- /dev/null +++ b/example-google.json @@ -0,0 +1,37 @@ +{ + "summary": "Flight to Minas Tirith (VG 1234)", + "uid": "loremipsum123@google.com", + "created": { + "date": "2024-09-17T20:07:20.000Z", + "type": "DATE-TIME" + }, + "lastModified": { + "date": "2024-09-17T20:07:20.000Z", + "type": "DATE-TIME" + }, + "stamp": { + "date": "2025-01-05T15:51:40.000Z", + "type": "DATE-TIME" + }, + "start": { + "date": "2024-10-28T18:05:00.000Z", + "type": "DATE-TIME" + }, + "location": "Shire (SHR)", + "description": "Example data from Google Calendar, as parsed by ts-ics\nit has newlines like this", + "timeTransparent": "TRANSPARENT", + "class": "PRIVATE", + "status": "CONFIRMED", + "attendees": [ + { + "email": "hobbit@example.com", + "name": "hobbit@example.com", + "role": "REQ-PARTICIPANT", + "partstat": "ACCEPTED" + } + ], + "end": { + "date": "2024-10-28T20:00:00.000Z", + "type": "DATE-TIME" + } +} diff --git a/icalendar.ts b/icalendar.ts index 50c4867..354f98d 100644 --- a/icalendar.ts +++ b/icalendar.ts @@ -1,20 +1,29 @@ -import { editor, system } from "@silverbulletmd/silverbullet/syscalls"; +import { system } from "@silverbulletmd/silverbullet/syscalls"; import { QueryProviderEvent } from "@silverbulletmd/silverbullet/types"; import { applyQuery } from "@silverbulletmd/silverbullet/lib/query"; import { parseIcsCalendar, type VCalendar } from "ts-ics"; +// Try to match SilverBullet properties where possible. +// Timestamps should be strings formatted with `localDateString` interface Event { + // Typically available in calendar apps summary: string | undefined; description: string | undefined; + location: string | undefined; + + // Same as SilverBullet pages created: string | undefined; lastModified: string | undefined; + // Keep consistent with dates above start: string | undefined; end: string | undefined; + + sourceName: string | undefined; } interface Source { - url: string; - name: string | undefined; + url: string; // Should be an .ics file + name: string | undefined; // Optional name that will be assigned to events } export async function queryEvents( @@ -37,22 +46,23 @@ export async function queryEvents( throw new Error("Didn't parse events from ics data"); } - console.log(JSON.stringify(calendarParsed.events[0], null, 2)); - + // The order here is the default order of columns without the select clause for (const icsEvent of calendarParsed.events) { events.push({ summary: icsEvent.summary, + sourceName: source.name, + + location: icsEvent.location, description: icsEvent.description, - // Mimic properties of pages + + start: localDateString(icsEvent.start.date), + end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined, created: icsEvent.created ? localDateString(icsEvent.created.date) : undefined, lastModified: icsEvent.lastModified ? localDateString(icsEvent.lastModified.date) : undefined, - // Consistent with formats above - start: localDateString(icsEvent.start.date), - end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined, }); } } catch (err) { @@ -69,6 +79,7 @@ async function getSources(): Promise { const config = await system.getSpaceConfig("icalendar", {}); if (!config.sources || !Array.isArray(config.sources)) { + // The queries are running on server, probably because of that, can't use editor.flashNotification console.error("Configure icalendar.sources"); return []; }