forked from GitHubMirrors/silverbullet-icalendar
Fix: Final verified build v0.3.13 with explicit naming and mapping
All checks were successful
Build SilverBullet Plug / build (push) Successful in 25s
All checks were successful
Build SilverBullet Plug / build (push) Successful in 25s
This commit is contained in:
4
PLUG.md
4
PLUG.md
@@ -1,8 +1,8 @@
|
||||
---
|
||||
name: Library/sstent/icalendar
|
||||
version: 0.3.12
|
||||
version: 0.3.13
|
||||
tags: meta/library
|
||||
files:
|
||||
- icalendar.plug.js
|
||||
---
|
||||
iCalendar sync plug for SilverBullet.
|
||||
iCalendar sync plug for SilverBullet.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
name: icalendar
|
||||
version: 0.3.12
|
||||
name: Library/sstent/icalendar
|
||||
version: 0.3.13
|
||||
author: sstent
|
||||
index: icalendar.ts
|
||||
functions:
|
||||
@@ -16,4 +16,4 @@ functions:
|
||||
path: icalendar.ts:showVersion
|
||||
command: "iCalendar: Show Version"
|
||||
permissions:
|
||||
- http
|
||||
- http
|
||||
|
||||
21
icalendar.ts
21
icalendar.ts
@@ -1,10 +1,11 @@
|
||||
import { clientStore, config, datastore, editor, index } from "@silverbulletmd/silverbullet/syscalls";
|
||||
import { convertIcsCalendar } from "https://esm.sh/ts-ics@2.4.0";
|
||||
import type { IcsEvent } from "https://esm.sh/ts-ics@2.4.0";
|
||||
|
||||
const VERSION = "0.3.12";
|
||||
const VERSION = "0.3.13";
|
||||
const CACHE_KEY = "icalendar:lastSync";
|
||||
|
||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
||||
|
||||
const TIMEZONE_OFFSETS: Record<string, number> = {
|
||||
"GMT Standard Time": 0,
|
||||
"W. Europe Standard Time": 1,
|
||||
@@ -31,8 +32,12 @@ async function getSources(): Promise<{ sources: any[], tzShift: number }> {
|
||||
}
|
||||
|
||||
async function fetchAndParseCalendar(source: any, hourShift = 0): Promise<any[]> {
|
||||
console.log(`[iCalendar] Fetching from ${source.url}`);
|
||||
const response = await fetch(source.url);
|
||||
if (!response.ok) return [];
|
||||
if (!response.ok) {
|
||||
console.error(`[iCalendar] Fetch failed with status ${response.status}`);
|
||||
return [];
|
||||
}
|
||||
const text = await response.text();
|
||||
const calendar = convertIcsCalendar(undefined, text);
|
||||
if (!calendar.events) return [];
|
||||
@@ -65,8 +70,10 @@ async function fetchAndParseCalendar(source: any, hourShift = 0): Promise<any[]>
|
||||
}
|
||||
|
||||
export async function syncCalendars() {
|
||||
console.log(`[iCalendar] syncCalendars command triggered`);
|
||||
try {
|
||||
const { sources, tzShift } = await getSources();
|
||||
console.log(`[iCalendar] Found ${sources.length} sources, tzShift: ${tzShift}`);
|
||||
if (sources.length === 0) return;
|
||||
await editor.flashNotification("Syncing calendars...", "info");
|
||||
const allEvents: any[] = [];
|
||||
@@ -75,18 +82,21 @@ export async function syncCalendars() {
|
||||
allEvents.push(...events);
|
||||
}
|
||||
await index.indexObjects("$icalendar", allEvents);
|
||||
console.log(`[iCalendar] Successfully indexed ${allEvents.length} events`);
|
||||
await editor.flashNotification(`Synced ${allEvents.length} events`, "info");
|
||||
} catch (err) {
|
||||
console.error("Sync failed:", err);
|
||||
console.error("[iCalendar] Sync failed:", err);
|
||||
}
|
||||
}
|
||||
|
||||
export async function forceSync() {
|
||||
console.log(`[iCalendar] forceSync command triggered`);
|
||||
await clientStore.del(CACHE_KEY);
|
||||
await syncCalendars();
|
||||
}
|
||||
|
||||
export async function clearCache() {
|
||||
console.log(`[iCalendar] clearCache command triggered`);
|
||||
if (!await editor.confirm("Clear all calendar events?")) return;
|
||||
const pageKeys = await datastore.query({ prefix: ["ridx", "$icalendar"] });
|
||||
const allKeys: any[] = [];
|
||||
@@ -100,5 +110,6 @@ export async function clearCache() {
|
||||
}
|
||||
|
||||
export async function showVersion() {
|
||||
console.log(`[iCalendar] showVersion command triggered`);
|
||||
await editor.flashNotification(`iCalendar Plug ${VERSION}`, "info");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user