gofmt -s -w .

This commit is contained in:
Nazar Kanaev 2021-04-06 08:43:15 +01:00
parent 614dcc8975
commit 2df2f41516
11 changed files with 30 additions and 34 deletions

View File

@ -2,10 +2,10 @@ package main
import ( import (
"fmt" "fmt"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
"io"
"strings" "strings"
"github.com/nkanaev/yarr/src/content/readability" "github.com/nkanaev/yarr/src/content/readability"

View File

@ -23,8 +23,7 @@ func TestQuery(t *testing.T) {
</html> </html>
`)) `))
nodes := Query(node, "p") nodes := Query(node, "p")
match := ( match := (len(nodes) == 1 &&
len(nodes) == 1 &&
nodes[0].Type == html.ElementNode && nodes[0].Type == html.ElementNode &&
nodes[0].Data == "p") nodes[0].Data == "p")
if !match { if !match {
@ -50,8 +49,7 @@ func TestQueryMulti(t *testing.T) {
</html> </html>
`)) `))
nodes := Query(node, "p , span") nodes := Query(node, "p , span")
match := ( match := (len(nodes) == 3 &&
len(nodes) == 3 &&
nodes[0].Type == html.ElementNode && nodes[0].Data == "p" && nodes[0].Type == html.ElementNode && nodes[0].Data == "p" &&
nodes[1].Type == html.ElementNode && nodes[1].Data == "p" && nodes[1].Type == html.ElementNode && nodes[1].Data == "p" &&
nodes[2].Type == html.ElementNode && nodes[2].Data == "span") nodes[2].Type == html.ElementNode && nodes[2].Data == "span")

View File

@ -3,7 +3,7 @@ package htmlutil
import "testing" import "testing"
func TestExtractText(t *testing.T) { func TestExtractText(t *testing.T) {
testcases := [][2]string { testcases := [][2]string{
{"hello", "<div>hello</div>"}, {"hello", "<div>hello</div>"},
{"hello world", "<div>hello</div> world"}, {"hello world", "<div>hello</div> world"},
{"helloworld", "<div>hello</div>world"}, {"helloworld", "<div>hello</div>world"},

View File

@ -129,10 +129,9 @@ func removeUnlikelyCandidates(root *html.Node) {
continue continue
} }
blacklisted := ( blacklisted := (blacklistCandidatesRegexp.MatchString(str) ||
blacklistCandidatesRegexp.MatchString(str) ||
(unlikelyCandidatesRegexp.MatchString(str) && (unlikelyCandidatesRegexp.MatchString(str) &&
!okMaybeItsACandidateRegexp.MatchString(str))) !okMaybeItsACandidateRegexp.MatchString(str)))
if blacklisted && node.Parent != nil { if blacklisted && node.Parent != nil {
node.Parent.RemoveChild(node) node.Parent.RemoveChild(node)
} }
@ -198,7 +197,7 @@ func getCandidates(root *html.Node) nodeScores {
// Scale the final candidates score based on link density. Good content // Scale the final candidates score based on link density. Good content
// should have a relatively small link density (5% or less) and be mostly // should have a relatively small link density (5% or less) and be mostly
// unaffected by this operation // unaffected by this operation
for node, _ := range scores { for node := range scores {
scores[node] *= (1 - getLinkDensity(node)) scores[node] *= (1 - getLinkDensity(node))
} }

View File

@ -138,19 +138,19 @@ var allowedTags = sset([]string{
"wbr", "wbr",
}) })
var allowedAttrs = map[string]set { var allowedAttrs = map[string]set{
"img": sset([]string{"alt", "title", "src", "srcset", "sizes"}), "img": sset([]string{"alt", "title", "src", "srcset", "sizes"}),
"audio": sset([]string{"src"}), "audio": sset([]string{"src"}),
"video": sset([]string{"poster", "height", "width", "src"}), "video": sset([]string{"poster", "height", "width", "src"}),
"source": sset([]string{"src", "type", "srcset", "sizes", "media"}), "source": sset([]string{"src", "type", "srcset", "sizes", "media"}),
"td": sset([]string{"rowspan", "colspan"}), "td": sset([]string{"rowspan", "colspan"}),
"th": sset([]string{"rowspan", "colspan"}), "th": sset([]string{"rowspan", "colspan"}),
"q": sset([]string{"cite"}), "q": sset([]string{"cite"}),
"a": sset([]string{"href", "title"}), "a": sset([]string{"href", "title"}),
"time": sset([]string{"datetime"}), "time": sset([]string{"datetime"}),
"abbr": sset([]string{"title"}), "abbr": sset([]string{"title"}),
"acronym": sset([]string{"title"}), "acronym": sset([]string{"title"}),
"iframe": sset([]string{"width", "height", "frameborder", "src", "allowfullscreen"}), "iframe": sset([]string{"width", "height", "frameborder", "src", "allowfullscreen"}),
} }
var allowedURISchemes = sset([]string{ var allowedURISchemes = sset([]string{

View File

@ -9,8 +9,8 @@ import (
var ( var (
youtubeFrame = `<iframe src="https://www.youtube.com/embed/%s" width="560" height="315" frameborder="0" allowfullscreen></iframe>` youtubeFrame = `<iframe src="https://www.youtube.com/embed/%s" width="560" height="315" frameborder="0" allowfullscreen></iframe>`
vimeoFrame = `<iframe src="https://player.vimeo.com/video/%s" width="640" height="360" frameborder="0" allowfullscreen></iframe>` vimeoFrame = `<iframe src="https://player.vimeo.com/video/%s" width="640" height="360" frameborder="0" allowfullscreen></iframe>`
vimeoRegex = regexp.MustCompile(`\/(\d+)$`) vimeoRegex = regexp.MustCompile(`\/(\d+)$`)
) )
func VideoIFrame(link string) string { func VideoIFrame(link string) string {

View File

@ -58,8 +58,8 @@ func (s *Server) handler() http.Handler {
} }
func (s *Server) handleIndex(c *router.Context) { func (s *Server) handleIndex(c *router.Context) {
c.HTML(http.StatusOK, assets.Template("index.html"), map[string]interface{} { c.HTML(http.StatusOK, assets.Template("index.html"), map[string]interface{}{
"settings": s.db.GetSettings(), "settings": s.db.GetSettings(),
"authenticated": s.Username != "" && s.Password != "", "authenticated": s.Username != "" && s.Password != "",
}) })
} }

View File

@ -241,5 +241,4 @@ func m04_item_podcasturl(tx *sql.Tx) error {
return err return err
} }
// TODO: description -> content // TODO: description -> content