Fix links and image sources in rss content
parent
b7cd1745b1
commit
6c40901465
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 {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func Test_Server(t *testing.T) {
|
|||
|
||||
for _, _ = range cases {
|
||||
var err error
|
||||
s, err := New(testPort, func(string, string, string, time.Duration) {}, func(string, int) (string, error) { return "", nil })
|
||||
s, err := New(testPort, func(string, string, string, time.Duration) {}, func(string, int) (string, error) { return "", nil }, func(string) (string, error) { return "", nil })
|
||||
if err != nil {
|
||||
t.Errorf("failed to create server: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue