diff --git a/pkg/htmltext/htmltext.go b/pkg/htmltext/htmltext.go index 7f8e6e07..0130d11f 100644 --- a/pkg/htmltext/htmltext.go +++ b/pkg/htmltext/htmltext.go @@ -75,11 +75,10 @@ func FetchExcerpt(html, trimMarker string, limit int) (text string) { runeText := []rune(text) if len(runeText) <= limit { text = string(runeText) - } else { - text = string(runeText[0:limit]) + return } - text += trimMarker + text = string(runeText[0:limit]) + trimMarker return } diff --git a/pkg/htmltext/htmltext_test.go b/pkg/htmltext/htmltext_test.go index 9e405541..f67a20db 100644 --- a/pkg/htmltext/htmltext_test.go +++ b/pkg/htmltext/htmltext_test.go @@ -50,6 +50,10 @@ func TestFetchExcerpt(t *testing.T) { expected = "hello你好😂..." text = FetchExcerpt("

hello你好😂world

", "...", 8) assert.Equal(t, expected, text) + + expected = "hello你好" + text = FetchExcerpt("

hello你好

", "...", 8) + assert.Equal(t, expected, text) } func TestUrlTitle(t *testing.T) {