rewriting readability

This commit is contained in:
Nazar Kanaev 2021-03-30 12:28:28 +01:00
parent ac36892150
commit 82586dedff
2 changed files with 5 additions and 5 deletions

View File

@ -22,7 +22,7 @@ func InnerHTML(node *html.Node) string {
func Attr(node *html.Node, key string) string {
for _, a := range node.Attr {
if a.Key == key {
if strings.EqualFold(a.Key, key) {
return a.Val
}
}

View File

@ -248,7 +248,7 @@ func scoreNode(s *goquery.Selection) *candidate {
c.score -= 5
}
c.score += getClassWeight(s)
c.score += getClassWeight(s.Get(0))
return c
}
@ -267,10 +267,10 @@ func getLinkDensity(s *goquery.Selection) float32 {
// Get an elements class/id weight. Uses regular expressions to tell if this
// element looks good or bad.
func getClassWeight(s *goquery.Selection) float32 {
func getClassWeight(node *html.Node) float32 {
weight := 0
class, _ := s.Attr("class")
id, _ := s.Attr("id")
class := htmlutil.Attr(node, "class")
id := htmlutil.Attr(node, "id")
if class != "" {
if negativeRegexp.MatchString(class) {