Clean and finalize with a link for v0.1

This commit is contained in:
Bel LaPointe
2018-10-10 19:39:54 -06:00
parent 78e38f84d1
commit a3b9ef5ce5
4 changed files with 19 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import (
"html"
"io/ioutil"
"net/http"
"net/url"
"regexp"
"strings"
"time"
@@ -22,10 +23,10 @@ type Item struct {
}
func (item *Item) String() string {
return fmt.Sprintf("Name %v, Link %v, Content %q, TS %v",
return fmt.Sprintf("Name %v, Link %v, Content %v, TS %v",
item.Name,
item.Link,
item.Content,
len(item.Content),
item.TS.Local(),
)
}
@@ -57,15 +58,22 @@ func fromGofeedItem(gfitem *gofeed.Item, filter string) *Item {
TS: *gofeedItemTS(gfitem),
}
content := gfitem.Content
if content == "" {
content = gfitem.Description
}
if content == "" {
content = contentFromLink(item.Link)
}
if unescaped, err := url.QueryUnescape(content); err == nil {
content = unescaped
}
if filter != "" {
r := regexp.MustCompile(filter)
matches := r.FindAllString(content, -1)
content = strings.Join(matches, "<br>")
}
content = cleanImgTags(content)
content = "<a href=\"" + gfitem.Link + "\">" + item.Name + "</a><br>" + content
item.Content = content
return item
}