Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions internal/reader/json/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ func (j *JSONAdapter) BuildFeed(baseURL string) *model.Feed {
// The entry title is optional, so we need to find a fallback.
if entry.Title == "" {
for _, value := range []string{item.Summary, item.ContentText, item.ContentHTML} {
value = strings.TrimSpace(value)
if value != "" {
entry.Title = sanitizer.TruncateHTML(value, 100)
break
if value = sanitizer.TruncateHTML(value, 100); value == "" {
continue
}

entry.Title = value
break
Comment on lines +86 to +91

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with

Suggested change
if value = sanitizer.TruncateHTML(value, 100); value == "" {
continue
}
entry.Title = value
break
if value = sanitizer.TruncateHTML(value, 100); value != "" {
entry.Title = value
break
}

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference, really. Makes more sense with #4356.

If you're interested in why the flatter code the better, see uudashr/gocognit with corresponding article and maybe see bkielbasa/cyclop too.

Not dying on that hill though, will make whatever fits here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion either way, I was just curious

}
}

Expand Down
10 changes: 3 additions & 7 deletions internal/reader/rdf/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type rdfAdapter struct {

func (r *rdfAdapter) buildFeed(baseURL string) *model.Feed {
feed := &model.Feed{
Title: stripTags(r.rdf.Channel.Title),
Title: sanitizer.StripTags(r.rdf.Channel.Title),
FeedURL: strings.TrimSpace(baseURL),
SiteURL: strings.TrimSpace(r.rdf.Channel.Link),
Description: strings.TrimSpace(r.rdf.Channel.Description),
Expand Down Expand Up @@ -95,17 +95,13 @@ func (r *rdfAdapter) buildFeed(baseURL string) *model.Feed {
// Populate the entry author.
switch {
case item.DublinCoreCreator != "":
entry.Author = stripTags(item.DublinCoreCreator)
entry.Author = sanitizer.StripTags(item.DublinCoreCreator)
case r.rdf.Channel.DublinCoreCreator != "":
entry.Author = stripTags(r.rdf.Channel.DublinCoreCreator)
entry.Author = sanitizer.StripTags(r.rdf.Channel.DublinCoreCreator)
}

feed.Entries = append(feed.Entries, entry)
}

return feed
}

func stripTags(value string) string {
return strings.TrimSpace(sanitizer.StripTags(value))
}
4 changes: 2 additions & 2 deletions internal/reader/rss/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func findFeedAuthor(rssChannel *rssChannel) string {
return ""
}

return strings.TrimSpace(sanitizer.StripTags(author))
return sanitizer.StripTags(author)
}

func findFeedTags(rssChannel *rssChannel) []string {
Expand Down Expand Up @@ -296,7 +296,7 @@ func findEntryAuthor(rssItem *rssItem) string {
return ""
}

return strings.TrimSpace(sanitizer.StripTags(author))
return sanitizer.StripTags(author)
}

func findEntryTags(rssItem *rssItem) []string {
Expand Down
2 changes: 1 addition & 1 deletion internal/reader/sanitizer/strip_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func StripTags(input string) string {
return ""
}

return dst.String()
return strings.TrimSpace(dst.String())
}

// stripIter iterates over the input [io.Reader] and calls the yield function for each [html.TextToken].
Expand Down
2 changes: 1 addition & 1 deletion internal/reader/sanitizer/strip_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "testing"

func TestStripTags(t *testing.T) {
input := `This <a href="/test.html">link is relative</a> and <strong>this</strong> image: <img src="../folder/image.png"/>`
expected := `This link is relative and this image: `
expected := `This link is relative and this image:`
output := StripTags(input)

if expected != output {
Expand Down
Loading