Skip to content

Commit

Permalink
🎨 社区图床更换新域名 Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 15, 2020
1 parent e16aa24 commit 187f212
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions util/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ import (
)

// CommunityFileURL is the community file service URL.
const CommunityFileURL = "https://img.hacpai.com"
const CommunityFileURL = "https://b3logfile.com"

// ImageSize returns image URL of Qiniu image processing style with the specified width and height.
func ImageSize(imageURL string, width, height int) string {
if strings.Contains(imageURL, "imageView") {
if !Uploaded(imageURL) || strings.Contains(imageURL, "imageView") || strings.Contains(imageURL, ".gif") {
return imageURL
}

return imageURL + "?imageView2/1/w/" + strconv.Itoa(width) + "/h/" + strconv.Itoa(height) + "/interlace/1/q/100"
}

// Uploaded checks whether the specified URL has uploaded.
func Uploaded(url string) bool {
return strings.HasPrefix(url, CommunityFileURL) || strings.HasPrefix(url, "https://img.hacpai.com")
}

// RandImage returns an image URL randomly for article thumbnail.
// https://github.com/88250/bing
func RandImage() string {
Expand Down
3 changes: 3 additions & 0 deletions util/markdowns.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func Markdown(mdText string) *MarkdownResult {
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(contentHTML))
doc.Find("img").Each(func(i int, ele *goquery.Selection) {
src, _ := ele.Attr("src")
if Uploaded(src) && !strings.Contains(src, ".gif") && !strings.Contains(src, "imageView") {
src += "?imageView2/2/w/1280/format/jpg/interlace/1/q/100"
}
ele.SetAttr("data-src", src)
ele.RemoveAttr("src")
})
Expand Down

0 comments on commit 187f212

Please sign in to comment.