aboutsummaryrefslogtreecommitdiffstats
path: root/models/item
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2018-01-29 19:27:42 -0800
committerAdam Mathes <adam@trenchant.org>2018-01-29 19:27:42 -0800
commit07346c765e008ad80c1665f69fc076b7eed95374 (patch)
treeaf862ad18ccb300111ddd85dc1fa38c993b7e228 /models/item
parent802fcd6135c9d78ab0f17dd6d1fd5a448a94787a (diff)
downloadneko-07346c765e008ad80c1665f69fc076b7eed95374.tar.gz
neko-07346c765e008ad80c1665f69fc076b7eed95374.tar.bz2
neko-07346c765e008ad80c1665f69fc076b7eed95374.zip
factor out filter policy
Diffstat (limited to 'models/item')
-rw-r--r--models/item/item.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/models/item/item.go b/models/item/item.go
index 38e3d2f..91335cf 100644
--- a/models/item/item.go
+++ b/models/item/item.go
@@ -68,6 +68,14 @@ func (i *Item) FullSave() {
}
}
+func filterPolicy() *bluemonday.Policy {
+ p := bluemonday.NewPolicy()
+ p.AllowElements("ul", "ol", "li", "blockquote", "a", "img", "p", "h1", "h2", "h3", "h4", "b", "i", "em", "strong")
+ p.AllowAttrs("href").OnElements("a")
+ p.AllowAttrs("src", "alt").OnElements("img")
+ return p
+}
+
func (i *Item) GetFullContent() {
g := goose.New()
article, err := g.ExtractFromURL(i.Url)
@@ -91,10 +99,7 @@ func (i *Item) GetFullContent() {
return
}
- p := bluemonday.NewPolicy()
- p.AllowElements("blockquote", "a", "img", "p", "h1", "h2", "h3", "h4", "b", "i", "em", "strong")
- p.AllowAttrs("href").OnElements("a")
- p.AllowAttrs("src", "alt").OnElements("img")
+ p := filterPolicy()
md = p.Sanitize(ht)
img = article.TopImage
@@ -147,10 +152,7 @@ func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([
}
defer rows.Close()
- p := bluemonday.NewPolicy()
- p.AllowElements("blockquote", "a", "img", "p", "h1", "h2", "h3", "h4", "b", "i", "em", "strong")
- p.AllowAttrs("href").OnElements("a")
- p.AllowAttrs("src", "alt").OnElements("img")
+ p := filterPolicy()
items := make([]*Item, 0)
for rows.Next() {
@@ -181,6 +183,7 @@ func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([
}
func (i *Item) CleanHeaderImage() {
+ // TODO: blacklist of bad imgs
if i.HeaderImage == "https://s0.wp.com/i/blank.jpg" {
i.HeaderImage = ""
}