Skip to content

Commit

Permalink
Trim spaces + option to ignore empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Ordspilleren committed Jun 27, 2021
1 parent cb0c865 commit 27c8454
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"type": "css",
"paths": ["#content > dl > dt:nth-child(3)", "#content > dl > dt:nth-child(5)"]
},
"filters": ["perfection", "success"]
"filters": ["perfection", "success"],
"ignoreEmpty": true
}
],
"notifiers": {
Expand Down
8 changes: 7 additions & 1 deletion monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Monitor struct {
Interval time.Duration `json:"interval"`
Selector Selector `json:"selector,omitempty"`
Filters Filters `json:"filters,omitempty"`
IgnoreEmpty bool `json:"ignoreEmpty,omitempty"`
notifierService NotifierService
started bool
doneChannel chan bool
Expand Down Expand Up @@ -226,6 +227,11 @@ func (m *Monitor) check() {
return
}

if m.IgnoreEmpty && processedContent == "" {
log.Print("Content is empty, ignoring...")
return
}

storageContent := m.storage.GetContent(m.id)

if compareContent(storageContent, processedContent) {
Expand Down Expand Up @@ -266,7 +272,7 @@ func processContent(content io.ReadCloser, selector Selector, filters Filters) (
selectorContent = processFilters(filters, selectorContent)
}

return selectorContent, nil
return strings.TrimSpace(selectorContent), nil
}

func processFilters(filters Filters, content string) string {
Expand Down

0 comments on commit 27c8454

Please sign in to comment.