package extractor import ( "bytes" "context" "net/url" "github.com/go-shiori/go-readability" ) func Readability(_ context.Context, doc Document) (Article, error) { data, err := doc.Content() if err != nil { return Article{}, err } u, err := url.Parse(doc.URL()) if err != nil { return Article{}, err } a, err := readability.FromReader(bytes.NewBufferString(data), u) if err != nil { return Article{}, err } pubTime := "" if a.PublishedTime != nil { pubTime = a.PublishedTime.Format("2006-01-02T15:04:05Z") } return Article{ Title: a.Title, Content: a.Content, TextContent: a.TextContent, Length: a.Length, Excerpt: a.Excerpt, Byline: a.Byline, SiteName: a.SiteName, Lang: a.Language, PublishedTime: pubTime, }, nil }