Fix links and image sources in rss content

This commit is contained in:
Bel LaPointe
2018-10-10 14:02:36 -06:00
parent b7cd1745b1
commit 6c40901465
2 changed files with 17 additions and 3 deletions

View File

@@ -60,7 +60,6 @@ func fromGofeedItem(gfitem *gofeed.Item, filter string) *Item {
if content == "" {
content = contentFromLink(item.Link)
}
content = strings.Replace(content, "\n", "", -1)
if filter != "" {
r := regexp.MustCompile(filter)
matches := r.FindAllString(content, -1)
@@ -81,7 +80,22 @@ func contentFromLink(link string) string {
if err != nil {
return ""
}
return string(b)
protocol := strings.Split(link, ":")[0] + "://"
if !strings.HasPrefix(protocol, "http") {
protocol = ""
}
content := strings.Replace(string(b), "\n", "", -1)
// fix all //img.link/something.jpg
badSrc := regexp.MustCompile("\"\\/\\/")
content = badSrc.ReplaceAllString(content, "\""+protocol)
// fix all href="/path/to"
host := protocol + strings.Split(link[len(protocol):], "/")[0] + "/"
badHref := regexp.MustCompile("href=\"\\/")
content = badHref.ReplaceAllString(content, "href=\""+host)
// fix all src="/path/to"
badPathSrc := regexp.MustCompile("src=\"\\/")
content = badPathSrc.ReplaceAllString(content, "src=\""+host)
return content
}
func cleanImgTags(s string) string {