From 1c65a596a4d70df21b7f81e6fbc1728eb615533c Mon Sep 17 00:00:00 2001 From: Mark Andrew Jaroski Date: Sun, 28 Jan 2024 18:43:36 +0100 Subject: [PATCH] Added transform to ordinary text fields --- scraper/scraper.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scraper/scraper.go b/scraper/scraper.go index 48d54ee..e39897d 100644 --- a/scraper/scraper.go +++ b/scraper/scraper.go @@ -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 @@ -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 {