From 2df2f415160d723f8cfbee948d77c3446420a896 Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Tue, 6 Apr 2021 08:43:15 +0100 Subject: [PATCH] gofmt -s -w . --- bin/reader.go | 2 +- src/content/htmlutil/query_test.go | 10 ++++------ src/content/htmlutil/utils_test.go | 2 +- src/content/readability/readability.go | 7 +++---- src/content/sanitizer/whitelist.go | 24 ++++++++++++------------ src/content/silo/iframe.go | 6 +++--- src/content/silo/iframe_test.go | 4 ++-- src/server/routes.go | 4 ++-- src/server/routes_test.go | 2 +- src/storage/migration.go | 1 - src/worker/worker.go | 2 +- 11 files changed, 30 insertions(+), 34 deletions(-) diff --git a/bin/reader.go b/bin/reader.go index f6ef76d..36b4805 100644 --- a/bin/reader.go +++ b/bin/reader.go @@ -2,10 +2,10 @@ package main import ( "fmt" + "io" "log" "net/http" "os" - "io" "strings" "github.com/nkanaev/yarr/src/content/readability" diff --git a/src/content/htmlutil/query_test.go b/src/content/htmlutil/query_test.go index b0ab50e..389ef8e 100644 --- a/src/content/htmlutil/query_test.go +++ b/src/content/htmlutil/query_test.go @@ -23,10 +23,9 @@ func TestQuery(t *testing.T) { `)) nodes := Query(node, "p") - match := ( - len(nodes) == 1 && + match := (len(nodes) == 1 && nodes[0].Type == html.ElementNode && - nodes[0].Data == "p") + nodes[0].Data == "p") if !match { t.Fatalf("incorrect match: %#v", nodes) } @@ -50,11 +49,10 @@ func TestQueryMulti(t *testing.T) { `)) nodes := Query(node, "p , span") - match := ( - len(nodes) == 3 && + match := (len(nodes) == 3 && nodes[0].Type == html.ElementNode && nodes[0].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") if !match { for i, n := range nodes { t.Logf("%d: %s", i, HTML(n)) diff --git a/src/content/htmlutil/utils_test.go b/src/content/htmlutil/utils_test.go index 4ab6251..eb9e522 100644 --- a/src/content/htmlutil/utils_test.go +++ b/src/content/htmlutil/utils_test.go @@ -3,7 +3,7 @@ package htmlutil import "testing" func TestExtractText(t *testing.T) { - testcases := [][2]string { + testcases := [][2]string{ {"hello", "
hello
"}, {"hello world", "
hello
world"}, {"helloworld", "
hello
world"}, diff --git a/src/content/readability/readability.go b/src/content/readability/readability.go index fd4c46d..324d7f3 100644 --- a/src/content/readability/readability.go +++ b/src/content/readability/readability.go @@ -129,10 +129,9 @@ func removeUnlikelyCandidates(root *html.Node) { continue } - blacklisted := ( - blacklistCandidatesRegexp.MatchString(str) || + blacklisted := (blacklistCandidatesRegexp.MatchString(str) || (unlikelyCandidatesRegexp.MatchString(str) && - !okMaybeItsACandidateRegexp.MatchString(str))) + !okMaybeItsACandidateRegexp.MatchString(str))) if blacklisted && node.Parent != nil { 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 // should have a relatively small link density (5% or less) and be mostly // unaffected by this operation - for node, _ := range scores { + for node := range scores { scores[node] *= (1 - getLinkDensity(node)) } diff --git a/src/content/sanitizer/whitelist.go b/src/content/sanitizer/whitelist.go index 4722c50..49b7577 100644 --- a/src/content/sanitizer/whitelist.go +++ b/src/content/sanitizer/whitelist.go @@ -138,19 +138,19 @@ var allowedTags = sset([]string{ "wbr", }) -var allowedAttrs = map[string]set { - "img": sset([]string{"alt", "title", "src", "srcset", "sizes"}), - "audio": sset([]string{"src"}), - "video": sset([]string{"poster", "height", "width", "src"}), - "source": sset([]string{"src", "type", "srcset", "sizes", "media"}), - "td": sset([]string{"rowspan", "colspan"}), - "th": sset([]string{"rowspan", "colspan"}), - "q": sset([]string{"cite"}), - "a": sset([]string{"href", "title"}), - "time": sset([]string{"datetime"}), - "abbr": sset([]string{"title"}), +var allowedAttrs = map[string]set{ + "img": sset([]string{"alt", "title", "src", "srcset", "sizes"}), + "audio": sset([]string{"src"}), + "video": sset([]string{"poster", "height", "width", "src"}), + "source": sset([]string{"src", "type", "srcset", "sizes", "media"}), + "td": sset([]string{"rowspan", "colspan"}), + "th": sset([]string{"rowspan", "colspan"}), + "q": sset([]string{"cite"}), + "a": sset([]string{"href", "title"}), + "time": sset([]string{"datetime"}), + "abbr": 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{ diff --git a/src/content/silo/iframe.go b/src/content/silo/iframe.go index 57fc6d6..af1770d 100644 --- a/src/content/silo/iframe.go +++ b/src/content/silo/iframe.go @@ -9,8 +9,8 @@ import ( var ( youtubeFrame = `` - vimeoFrame = `` - vimeoRegex = regexp.MustCompile(`\/(\d+)$`) + vimeoFrame = `` + vimeoRegex = regexp.MustCompile(`\/(\d+)$`) ) func VideoIFrame(link string) string { @@ -31,7 +31,7 @@ func VideoIFrame(link string) string { if l.Host == "vimeo.com" { if matches := vimeoRegex.FindStringSubmatch(l.Path); len(matches) > 0 { - return fmt.Sprintf(vimeoFrame, matches[1]) + return fmt.Sprintf(vimeoFrame, matches[1]) } } return "" diff --git a/src/content/silo/iframe_test.go b/src/content/silo/iframe_test.go index 1b88802..0a8f83f 100644 --- a/src/content/silo/iframe_test.go +++ b/src/content/silo/iframe_test.go @@ -9,7 +9,7 @@ func TestYoutubeIframe(t *testing.T) { "https://youtu.be/dQw4w9WgXcQ", } for _, link := range links { - have := VideoIFrame(link) + have := VideoIFrame(link) want := `` if have != want { t.Logf("want: %s", want) @@ -25,7 +25,7 @@ func TestVimeoIframe(t *testing.T) { "https://vimeo.com/526381128", } for _, link := range links { - have := VideoIFrame(link) + have := VideoIFrame(link) want := `` if have != want { t.Logf("want: %s", want) diff --git a/src/server/routes.go b/src/server/routes.go index 0798739..d41b15c 100644 --- a/src/server/routes.go +++ b/src/server/routes.go @@ -58,8 +58,8 @@ func (s *Server) handler() http.Handler { } func (s *Server) handleIndex(c *router.Context) { - c.HTML(http.StatusOK, assets.Template("index.html"), map[string]interface{} { - "settings": s.db.GetSettings(), + c.HTML(http.StatusOK, assets.Template("index.html"), map[string]interface{}{ + "settings": s.db.GetSettings(), "authenticated": s.Username != "" && s.Password != "", }) } diff --git a/src/server/routes_test.go b/src/server/routes_test.go index 23d0a53..9b82442 100644 --- a/src/server/routes_test.go +++ b/src/server/routes_test.go @@ -20,7 +20,7 @@ func TestStatic(t *testing.T) { func TestStaticWithBase(t *testing.T) { server := NewServer(nil, "127.0.0.1:8000") server.BasePath = "/sub" - + handler := server.handler() url := "/sub/static/javascripts/app.js" diff --git a/src/storage/migration.go b/src/storage/migration.go index 9b2996f..58d2c02 100644 --- a/src/storage/migration.go +++ b/src/storage/migration.go @@ -241,5 +241,4 @@ func m04_item_podcasturl(tx *sql.Tx) error { return err } - // TODO: description -> content diff --git a/src/worker/worker.go b/src/worker/worker.go index 8b07025..523b0fe 100644 --- a/src/worker/worker.go +++ b/src/worker/worker.go @@ -106,7 +106,7 @@ func (w *Worker) refresher() { srcqueue := make(chan storage.Feed, len(feeds)) dstqueue := make(chan []storage.Item) - + // hardcoded to 4 workers ;) go w.worker(srcqueue, dstqueue) go w.worker(srcqueue, dstqueue)