diff --git a/mail/mail.html b/mail/mail.html
index 5f6d1e2..390a906 100644
--- a/mail/mail.html
+++ b/mail/mail.html
@@ -79,14 +79,14 @@
Daily Beauty 表特日報
本日精選
{{ range $.Beauties }}
- {{ .Title }}
+ {{ .Title }}({{ .NImage }}圖)
{{ end }}
隨機推薦
- {{ $.RandomBeauty.Title }}
+ {{ $.RandomBeauty.Title }}({{ $.RandomBeauty.NImage }}圖)
@@ -96,7 +96,7 @@ {{ $.RandomBeauty.Title }}
如果不想再收到了可以
取消訂閱
diff --git a/model/beauty.go b/model/beauty.go
index 443e756..b411c6f 100644
--- a/model/beauty.go
+++ b/model/beauty.go
@@ -3,6 +3,7 @@ package model
// Beauty is a struct from getDailyBeauties api
type Beauty struct {
NVote int
+ NImage int
Title string
Href string
PreviewImg string
diff --git a/model/post.go b/model/post.go
index b3f3979..9539e7d 100644
--- a/model/post.go
+++ b/model/post.go
@@ -25,7 +25,20 @@ func fetchPreviewImg(p *Post) string {
return imgURL
}
-// [正妹] 大橋未久 -> 大橋未久
+// fetchImageAmount get the amount of images in a post
+func fetchImageAmount(p *Post) int {
+ // TODO: handle error
+ doc, _ := goquery.NewDocument(p.Href)
+ doc.Find("div.push").Each(func(i int, s *goquery.Selection) {
+ // remove push comment
+ s.Remove()
+ })
+ imgSelector := `#main-content a[href$=".jpg"],a[href$=".png"],a[href$=".gif"]`
+ nImage := doc.Find(imgSelector).Size()
+ return nImage
+}
+
+// "[正妹] 大橋未久" -> "大橋未久"
func trimTitlePrefix(title string) string {
return strings.TrimPrefix(title, "[正妹] ")
}
@@ -41,8 +54,10 @@ func transformURL(pttURL string) string {
// ToBeauty transform a Post to a Beauty
func (p *Post) ToBeauty() Beauty {
previewImg := fetchPreviewImg(p)
+ nImage := fetchImageAmount(p)
return Beauty{
NVote: p.NVote,
+ NImage: nImage,
Title: trimTitlePrefix(p.Title),
Href: transformURL(p.Href),
PreviewImg: previewImg,