forked from GitHubMirrors/silverbullet-icalendar
Define the event object
This commit is contained in:
@@ -44,9 +44,6 @@ select summary, description
|
|||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- Decide which properties should be exposed:
|
|
||||||
- Location
|
|
||||||
- Color?
|
|
||||||
- Add instructions for popular services:
|
- Add instructions for popular services:
|
||||||
- Nextcloud
|
- Nextcloud
|
||||||
- Google Calendar
|
- Google Calendar
|
||||||
|
|||||||
37
example-google.json
Normal file
37
example-google.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
29
icalendar.ts
29
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 { QueryProviderEvent } from "@silverbulletmd/silverbullet/types";
|
||||||
import { applyQuery } from "@silverbulletmd/silverbullet/lib/query";
|
import { applyQuery } from "@silverbulletmd/silverbullet/lib/query";
|
||||||
import { parseIcsCalendar, type VCalendar } from "ts-ics";
|
import { parseIcsCalendar, type VCalendar } from "ts-ics";
|
||||||
|
|
||||||
|
// Try to match SilverBullet properties where possible.
|
||||||
|
// Timestamps should be strings formatted with `localDateString`
|
||||||
interface Event {
|
interface Event {
|
||||||
|
// Typically available in calendar apps
|
||||||
summary: string | undefined;
|
summary: string | undefined;
|
||||||
description: string | undefined;
|
description: string | undefined;
|
||||||
|
location: string | undefined;
|
||||||
|
|
||||||
|
// Same as SilverBullet pages
|
||||||
created: string | undefined;
|
created: string | undefined;
|
||||||
lastModified: string | undefined;
|
lastModified: string | undefined;
|
||||||
|
// Keep consistent with dates above
|
||||||
start: string | undefined;
|
start: string | undefined;
|
||||||
end: string | undefined;
|
end: string | undefined;
|
||||||
|
|
||||||
|
sourceName: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Source {
|
interface Source {
|
||||||
url: string;
|
url: string; // Should be an .ics file
|
||||||
name: string | undefined;
|
name: string | undefined; // Optional name that will be assigned to events
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function queryEvents(
|
export async function queryEvents(
|
||||||
@@ -37,22 +46,23 @@ export async function queryEvents(
|
|||||||
throw new Error("Didn't parse events from ics data");
|
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) {
|
for (const icsEvent of calendarParsed.events) {
|
||||||
events.push({
|
events.push({
|
||||||
summary: icsEvent.summary,
|
summary: icsEvent.summary,
|
||||||
|
sourceName: source.name,
|
||||||
|
|
||||||
|
location: icsEvent.location,
|
||||||
description: icsEvent.description,
|
description: icsEvent.description,
|
||||||
// Mimic properties of pages
|
|
||||||
|
start: localDateString(icsEvent.start.date),
|
||||||
|
end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined,
|
||||||
created: icsEvent.created
|
created: icsEvent.created
|
||||||
? localDateString(icsEvent.created.date)
|
? localDateString(icsEvent.created.date)
|
||||||
: undefined,
|
: undefined,
|
||||||
lastModified: icsEvent.lastModified
|
lastModified: icsEvent.lastModified
|
||||||
? localDateString(icsEvent.lastModified.date)
|
? localDateString(icsEvent.lastModified.date)
|
||||||
: undefined,
|
: undefined,
|
||||||
// Consistent with formats above
|
|
||||||
start: localDateString(icsEvent.start.date),
|
|
||||||
end: icsEvent.end ? localDateString(icsEvent.end.date) : undefined,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -69,6 +79,7 @@ async function getSources(): Promise<Source[]> {
|
|||||||
const config = await system.getSpaceConfig("icalendar", {});
|
const config = await system.getSpaceConfig("icalendar", {});
|
||||||
|
|
||||||
if (!config.sources || !Array.isArray(config.sources)) {
|
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");
|
console.error("Configure icalendar.sources");
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user