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

Skip to content

Commit 0457092

Browse files
committed
img src : relative path -> abs path
1 parent 1b08208 commit 0457092

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
@@ -120,6 +120,16 @@ func ParseArticle(articleUrl string, auto bool) (*model.Article, error) {
120120
title = strings.TrimSpace(replacer.Replace(title))
121121

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

0 commit comments

Comments
 (0)