Fix links and image sources in rss content
This commit is contained in:
18
rss/item.go
18
rss/item.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user