Merge branch 'main' into feat-match-empty-description-location

This commit is contained in:
2024-08-25 23:13:48 +01:00
committed by GitHub
2 changed files with 20 additions and 6 deletions

View File

@@ -16,10 +16,11 @@ import (
// CalendarConfig definition
type CalendarConfig struct {
Name string `yaml:"name"`
Token string `yaml:"token"`
FeedURL string `yaml:"feed_url"`
Filters []Filter `yaml:"filters"`
Name string `yaml:"name"`
PublishName string `yaml:"publish_name"`
Token string `yaml:"token"`
FeedURL string `yaml:"feed_url"`
Filters []Filter `yaml:"filters"`
}
// Downloads iCal feed from the URL and applies filtering rules
@@ -44,6 +45,10 @@ func (calendarConfig CalendarConfig) fetch() ([]byte, error) {
return nil, err
}
if (calendarConfig.PublishName != "") {
cal.SetName(calendarConfig.PublishName)
}
// process filters
if len(calendarConfig.Filters) > 0 {
slog.Debug("Processing filters", "calendar", calendarConfig.Name)
@@ -153,8 +158,8 @@ func (filter Filter) matchesEvent(event ics.VEvent) bool {
return false // event doesn't match
}
}
// Check Description filters against VEvent
// Check Location filters against VEvent
if filter.Match.Location.hasConditions() {
eventLocation := event.GetProperty(ics.ComponentPropertyLocation)
var eventLocationValue string
@@ -191,6 +196,13 @@ func (filter Filter) transformEvent(event *ics.VEvent) {
} else if filter.Transform.Description.Replace != "" {
event.SetDescription(filter.Transform.Description.Replace)
}
// Location transformations
if filter.Transform.Location.Remove {
event.SetLocation("")
} else if filter.Transform.Location.Replace != "" {
event.SetLocation(filter.Transform.Location.Replace)
}
}
// EventMatchRules contains VEvent properties that user can match against