Skip to content

Commit

Permalink
Added transform to ordinary text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkJaroski committed Jan 28, 2024
1 parent ae1d021 commit 1c65a59
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type Field struct {
DateLanguage string `yaml:"date_language,omitempty"` // applies to date
Hide bool `yaml:"hide,omitempty"` // applies to text, url, date
GuessYear bool `yaml:"guess_year,omitempty"` // applies to date
// This comment is here to avoid a larger whitespace change in my pull request
Transform []TransformConfig `yaml:"transform,omitempty"`
}

type ElementLocations []ElementLocation
Expand Down Expand Up @@ -543,6 +545,14 @@ func extractField(field *Field, event map[string]interface{}, s *goquery.Selecti
if !field.CanBeEmpty && t == "" {
return fmt.Errorf("field %s cannot be empty", field.Name)
}
// transform the string if required
for _, tr := range field.Transform {
var err error
t, err = transformString(&tr, t)
if err != nil {
return err
}
}
event[field.Name] = t
case "url":
if len(field.ElementLocations) != 1 {
Expand Down

0 comments on commit 1c65a59

Please sign in to comment.