Skip to content

Commit 5669461

Browse files
committed
Remove description length limit
1 parent 89488cf commit 5669461

File tree

5 files changed

+3
-66
lines changed

5 files changed

+3
-66
lines changed

export_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ package feeder
22

33
var ExportItemConvert = (*Item).convert
44
var ExportFeedConvert = (*Feed).convert
5-
6-
var ExportItemsLimitDescription = (*Items).limitDescription

feeder.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package feeder
22

33
import (
44
ogp "github.com/otiai10/opengraph"
5-
"golang.org/x/exp/utf8string"
65
"log"
76
"sync"
87
"time"
@@ -87,24 +86,11 @@ func Crawl(fetchers ...Fetcher) *Items {
8786
}
8887
wg.Wait()
8988

90-
items.limitDescription(200)
91-
9289
fetchOGP(items)
9390

9491
return items
9592
}
9693

97-
func (items *Items) limitDescription(limit int) {
98-
for _, i := range items.Items {
99-
length := utf8string.NewString(i.Description).RuneCount()
100-
maxLength := limit
101-
if length < limit {
102-
maxLength = length
103-
}
104-
i.Description = utf8string.NewString(i.Description).Slice(0, maxLength)
105-
}
106-
}
107-
10894
func fetchOGP(items *Items) *Items {
10995
wg := sync.WaitGroup{}
11096

feeder_test.go

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package feeder_test
22

33
import (
4+
"github.com/kr/pretty"
5+
"github.com/naoki-kishi/feeder"
46
"reflect"
57
"strconv"
6-
"strings"
78
"testing"
89
"time"
9-
"unicode/utf8"
10-
11-
"github.com/kr/pretty"
12-
"github.com/naoki-kishi/feeder"
1310
)
1411

1512
type mockFetcher struct {
@@ -96,40 +93,3 @@ func TestCrawl(t *testing.T) {
9693

9794
}
9895
}
99-
100-
func TestItems_limitDescription(t *testing.T) {
101-
type fields struct {
102-
Items []*feeder.Item
103-
}
104-
type args struct {
105-
limit int
106-
}
107-
tests := []struct {
108-
name string
109-
fields fields
110-
args args
111-
}{
112-
{
113-
name: "longer than limit",
114-
fields: fields{Items: []*feeder.Item{
115-
{Description: strings.Repeat("a", 300)},
116-
}},
117-
args: args{limit: 200},
118-
},
119-
}
120-
for _, tt := range tests {
121-
t.Run(tt.name, func(t *testing.T) {
122-
items := &feeder.Items{
123-
Items: tt.fields.Items,
124-
}
125-
feeder.ExportItemsLimitDescription(items, tt.args.limit)
126-
127-
for _, i := range items.Items {
128-
got := utf8.RuneCountInString(i.Description)
129-
if tt.args.limit < got {
130-
t.Errorf("Exceed string length limit. limit=%d got=%d", tt.args.limit, got)
131-
}
132-
}
133-
})
134-
}
135-
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ require (
1010
github.com/otiai10/opengraph v1.0.0
1111
github.com/pkg/errors v0.8.1
1212
github.com/stretchr/testify v1.3.0 // indirect
13-
golang.org/x/exp v0.0.0-20190316020145-860388717186
13+
golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
1414
)

go.sum

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
22
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
3-
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
43
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
54
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
65
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -26,13 +25,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
2625
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
2726
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2827
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
29-
golang.org/x/exp v0.0.0-20190316020145-860388717186 h1:WVLLpyUE5WfDFkoRe+vPPFxVzwDwXwwG197QU7doL0M=
30-
golang.org/x/exp v0.0.0-20190316020145-860388717186/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
31-
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
32-
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
3328
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
3429
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3530
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
36-
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3731
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
38-
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=

0 commit comments

Comments
 (0)