Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec7067d

Browse files
committed
Merge pull request #11 from lewgun/master
img src : relative path -> abs path
2 parents 21fb12b + 0457092 commit ec7067d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

websites/code/studygolang/src/service/article.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ func ParseArticle(articleUrl string, auto bool) (*model.Article, error) {
122122
title = strings.TrimSpace(replacer.Replace(title))
123123

124124
contentSelection := doc.Find(rule.Content)
125+
126+
// relative url -> abs url
127+
contentSelection.Find("img").Each(func(i int, s *goquery.Selection) {
128+
if v, ok := s.Attr("src"); ok {
129+
if !strings.HasPrefix(v, "http") {
130+
s.SetAttr("src", domain+v)
131+
}
132+
}
133+
})
134+
125135
content, err := contentSelection.Html()
126136
if err != nil {
127137
logger.Errorln("goquery parse content error:", err)

0 commit comments

Comments
 (0)