mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 09:55:36 +00:00
fix readability edge case
This commit is contained in:
@@ -6,6 +6,7 @@ package readability
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
@@ -59,6 +60,9 @@ func ExtractContent(page io.Reader) (string, error) {
|
||||
best = body
|
||||
break
|
||||
}
|
||||
if best == nil {
|
||||
return "", errors.New("failed to extract content")
|
||||
}
|
||||
}
|
||||
//log.Printf("[Readability] TopCandidate: %v", topCandidate)
|
||||
|
||||
|
@@ -474,8 +474,9 @@ func (s *Server) handlePageCrawl(c *router.Context) {
|
||||
}
|
||||
content, err := readability.ExtractContent(strings.NewReader(body))
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
c.Out.WriteHeader(http.StatusNoContent)
|
||||
c.JSON(http.StatusOK, map[string]string{
|
||||
"content": "error: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
content = sanitizer.Sanitize(url, content)
|
||||
|
Reference in New Issue
Block a user