@@ -40,14 +40,33 @@ export default class ICSPlugin extends Plugin {
40
40
await this . saveSettings ( ) ;
41
41
}
42
42
43
+ formatEvent ( e : IEvent ) : string {
44
+ const callLinkOrLocation = e . callType ? `[${ e . callType } ](${ e . callUrl } )` : e . location ;
45
+
46
+ // Conditionally format start and end time based on dataViewSyntax setting
47
+ const startTimeFormatted = this . data . format . dataViewSyntax ? `[startTime:: ${ e . time } ]` : `${ e . time } ` ;
48
+ const endTimeFormatted = e . format . includeEventEndTime ? ( this . data . format . dataViewSyntax ? `[endTime:: ${ e . endTime } ]` : `- ${ e . endTime } ` ) : '' ;
49
+
50
+ // Combine all parts of the formatted event string
51
+ return [
52
+ `- ${ e . format . checkbox ? '[ ]' : '' } ` ,
53
+ startTimeFormatted ,
54
+ endTimeFormatted ,
55
+ e . format . icsName ? e . icsName : '' ,
56
+ e . format . summary ? e . summary : '' ,
57
+ e . format . location ? callLinkOrLocation : '' ,
58
+ e . format . description && e . description ? `\n\t- ${ e . description } ` : '' ,
59
+ ] . filter ( Boolean ) . join ( ' ' ) . trim ( ) ;
60
+ }
61
+
43
62
async getEvents ( date : string ) : Promise < IEvent [ ] > {
44
63
let events : IEvent [ ] = [ ] ;
45
64
let errorMessages : string [ ] = [ ] ; // To store error messages
46
-
65
+
47
66
for ( const calendar in this . data . calendars ) {
48
67
const calendarSetting = this . data . calendars [ calendar ] ;
49
68
let icsArray : any [ ] = [ ] ;
50
-
69
+
51
70
// Exception handling for downloading
52
71
try {
53
72
icsArray = parseIcs ( await request ( {
@@ -59,11 +78,11 @@ export default class ICSPlugin extends Plugin {
59
78
}
60
79
61
80
var dateEvents ;
62
-
81
+
63
82
// Exception handling for parsing and filtering
64
83
try {
65
84
dateEvents = filterMatchingEvents ( icsArray , date ) ;
66
-
85
+
67
86
} catch ( filterError ) {
68
87
console . error ( `Error filtering events for calendar ${ calendarSetting . icsName } : ${ filterError } ` ) ;
69
88
errorMessages . push ( `Error filtering events in calendar "${ calendarSetting . icsName } "` ) ;
@@ -72,7 +91,7 @@ export default class ICSPlugin extends Plugin {
72
91
try {
73
92
dateEvents . forEach ( ( e ) => {
74
93
const { callUrl, callType } = extractMeetingInfo ( e ) ;
75
-
94
+
76
95
let event : IEvent = {
77
96
utime : moment ( e . start ) . format ( 'X' ) ,
78
97
time : moment ( e . start ) . format ( this . data . format . timeFormat ) ,
@@ -92,15 +111,15 @@ export default class ICSPlugin extends Plugin {
92
111
errorMessages . push ( `Error parsing events in calendar "${ calendarSetting . icsName } "` ) ;
93
112
}
94
113
}
95
-
114
+
96
115
// Notify the user if any errors were encountered
97
116
if ( errorMessages . length > 0 ) {
98
117
const message = `Encountered ${ errorMessages . length } error(s) while processing calendars:\n\n${ errorMessages . join ( '\n' ) } \nSee console for details.` ;
99
118
new Notice ( message ) ;
100
119
}
101
-
120
+
102
121
return events ;
103
- }
122
+ }
104
123
105
124
async onload ( ) {
106
125
await this . loadSettings ( ) ;
@@ -112,18 +131,7 @@ export default class ICSPlugin extends Plugin {
112
131
const fileDate = getDateFromFile ( view . file , "day" ) . format ( "YYYY-MM-DD" ) ;
113
132
var events : any [ ] = await this . getEvents ( fileDate ) ;
114
133
115
- const mdArray = events . sort ( ( a , b ) => a . utime - b . utime ) . map ( e => {
116
- const callLinkOrlocation = e . callType ? `[${ e . callType } ](${ e . callUrl } )` : e . location ;
117
- return [
118
- `- ${ e . format ?. checkbox ? '[ ]' : '' } ` ,
119
- `${ e . time } ` ,
120
- e . format ?. includeEventEndTime ? `- ${ e . endTime } ` : null ,
121
- e . format ?. icsName ? e . icsName : null ,
122
- e . format ?. summary ? e . summary : null ,
123
- e . format ?. location ? callLinkOrlocation : null ,
124
- e . format ?. description && e . description ? `\n\t- ${ e . description } ` : null ,
125
- ] . filter ( Boolean ) . join ( ' ' )
126
- } ) ;
134
+ const mdArray = events . sort ( ( a , b ) => a . utime - b . utime ) . map ( this . formatEvent , this ) ;
127
135
editor . replaceRange ( mdArray . join ( "\n" ) , editor . getCursor ( ) ) ;
128
136
}
129
137
} ) ;
0 commit comments