* Create a new note from an ICS event
(
icsEvent: ICSEvent,
overrides?: { title?: string; folder?: string; template?: string }
)
| 358 | * Create a new note from an ICS event |
| 359 | */ |
| 360 | async createNoteFromICS( |
| 361 | icsEvent: ICSEvent, |
| 362 | overrides?: { title?: string; folder?: string; template?: string } |
| 363 | ): Promise<{ file: TFile; noteInfo: NoteInfo }> { |
| 364 | try { |
| 365 | // Get the subscription name for context |
| 366 | const subscription = this.plugin.icsSubscriptionService |
| 367 | .getSubscriptions() |
| 368 | .find((sub) => sub.id === icsEvent.subscriptionId); |
| 369 | const subscriptionName = subscription?.name || "Unknown Calendar"; |
| 370 | |
| 371 | // For all-day events with date-only format (YYYY-MM-DD), append T00:00:00 to parse as local midnight |
| 372 | const startDateStr = |
| 373 | icsEvent.allDay && /^\d{4}-\d{2}-\d{2}$/.test(icsEvent.start) |
| 374 | ? icsEvent.start + "T00:00:00" |
| 375 | : icsEvent.start; |
| 376 | const eventStartDate = new Date(startDateStr); |
| 377 | |
| 378 | // Determine note title |
| 379 | const noteTitle = |
| 380 | overrides?.title || `${icsEvent.title} - ${format(eventStartDate, "PPP")}`; |
| 381 | |
| 382 | // Determine folder (safely handle missing icsIntegration settings) |
| 383 | const rawFolder = |
| 384 | overrides?.folder || this.plugin.settings.icsIntegration?.defaultNoteFolder || ""; |
| 385 | |
| 386 | // Process folder template with ICS-specific data |
| 387 | const folder = processFolderTemplate(rawFolder, { |
| 388 | date: eventStartDate, |
| 389 | icsData: { |
| 390 | title: icsEvent.title, |
| 391 | location: icsEvent.location, |
| 392 | description: icsEvent.description, |
| 393 | }, |
| 394 | }); |
| 395 | |
| 396 | // Generate filename context for ICS events |
| 397 | // Use clean event title for filename template variables, not the formatted noteTitle |
| 398 | const filenameContext: ICSFilenameContext = { |
| 399 | title: icsEvent.title, // Use clean event title for {title} variable |
| 400 | priority: "", |
| 401 | status: "", |
| 402 | date: eventStartDate, |
| 403 | dueDate: icsEvent.end, |
| 404 | scheduledDate: icsEvent.start, |
| 405 | icsEventTitle: icsEvent.title, |
| 406 | icsEventLocation: icsEvent.location, |
| 407 | icsEventDescription: icsEvent.description, |
| 408 | }; |
| 409 | |
| 410 | // Generate unique filename using ICS-specific filename generator |
| 411 | const baseFilename = generateICSNoteFilename(filenameContext, this.plugin.settings); |
| 412 | const uniqueFilename = await generateUniqueFilename( |
| 413 | baseFilename, |
| 414 | folder, |
| 415 | this.plugin.app.vault |
| 416 | ); |
| 417 | const fullPath = folder ? `${folder}/${uniqueFilename}.md` : `${uniqueFilename}.md`; |
no test coverage detected