Load reads from the io.Reader and returns a single document with the data.
(_ context.Context)
| 25 | |
| 26 | // Load reads from the io.Reader and returns a single document with the data. |
| 27 | func (h HTML) Load(_ context.Context) ([]schema.Document, error) { |
| 28 | doc, err := goquery.NewDocumentFromReader(h.r) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | |
| 33 | var sel *goquery.Selection |
| 34 | if doc.Has("body") != nil { |
| 35 | sel = doc.Find("body").Contents() |
| 36 | } else { |
| 37 | sel = doc.Contents() |
| 38 | } |
| 39 | |
| 40 | sanitized := bluemonday.UGCPolicy().Sanitize(sel.Text()) |
| 41 | pagecontent := strings.TrimSpace(sanitized) |
| 42 | |
| 43 | return []schema.Document{ |
| 44 | { |
| 45 | PageContent: pagecontent, |
| 46 | Metadata: map[string]any{}, |
| 47 | }, |
| 48 | }, nil |
| 49 | } |
| 50 | |
| 51 | // LoadAndSplit reads text data from the io.Reader and splits it into multiple |
| 52 | // documents using a text splitter. |
no outgoing calls