Browse Source

路演精华摘要内容被截取

xingzai 3 years ago
parent
commit
4f9d99ebef
2 changed files with 13 additions and 1 deletions
  1. 1 1
      controllers/report.go
  2. 12 0
      services/article.go

+ 1 - 1
controllers/report.go

@@ -1717,7 +1717,7 @@ func (this *ReportController) RoadshowDetail() {
 			return
 		}
 		detail.Body = html.UnescapeString(detail.Body)
-		detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
+		detail.Abstract, _ = services.GetReportContentTextSubNew(detail.Abstract)
 		detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
 		detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
 		if detail.ReportLink == "0" {

+ 12 - 0
services/article.go

@@ -56,6 +56,18 @@ func GetReportContentTextSub(content string) (contentSub string, err error) {
 	return
 }
 
+func GetReportContentTextSubNew(content string) (contentSub string, err error) {
+	content = html.UnescapeString(content)
+	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+	docText := doc.Text()
+	bodyRune := []rune(docText)
+	bodyRuneLen := len(bodyRune)
+	body := string(bodyRune[:bodyRuneLen])
+	contentSub = body
+	contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
+	return
+}
+
 //解析文章内容
 func GetArticleAll() {
 	var err error