Explorar o código

文章列表页开始内容是图片

xingzai %!s(int64=3) %!d(string=hai) anos
pai
achega
925faf9c51
Modificáronse 3 ficheiros con 3 adicións e 21 borrados
  1. 2 2
      controllers/home.go
  2. 1 0
      models/article.go
  3. 0 19
      services/article.go

+ 2 - 2
controllers/home.go

@@ -92,7 +92,6 @@ func (this *HomeController) ListHome() {
 	if userType == 1 {
 		condition += ` AND  category_name  NOT LIKE '%研选` + `%'`
 	}
-	//condition = ` AND a.category_id NOT IN (85,71) `
 	total, err = models.GetHomeCount(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"
@@ -109,7 +108,8 @@ func (this *HomeController) ListHome() {
 	lenList := len(list)
 	for i := 0; i < lenList; i++ {
 		item := list[i]
-		//list[i].Body, _ = services.GetReportContentTextSub(item.Body)
+		list[i].BodyHtml = list[i].Body
+		list[i].Body, _ = services.GetReportContentTextSub(item.Body)
 		list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
 		if strings.Contains(item.CategoryName, "研选") {
 			list[i].IsResearch = true

+ 1 - 0
models/article.go

@@ -86,6 +86,7 @@ type HomeArticle struct {
 	CreateDate       string `description:"创建时间"`
 	PublishDate      string `description:"发布时间"`
 	Body             string `description:"内容"`
+	BodyHtml         string `description:"内容带有HTML标签"`
 	Abstract         string `description:"摘要"`
 	CategoryName     string `description:"一级分类"`
 	SubCategoryName  string `description:"二级分类"`

+ 0 - 19
services/article.go

@@ -42,25 +42,6 @@ func GetReportContentSub(content string) (contentSub string, err error) {
 func GetReportContentTextSub(content string) (contentSub string, err error) {
 	content = html.UnescapeString(content)
 	doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
-	//if err != nil {
-	//	fmt.Println("create doc err:", err.Error())
-	//	return
-	//}
-	//doc.Find("p").Each(func(i int, s *goquery.Selection) {
-	//	pHtml, _ := s.Html()
-	//	if strings.Contains(pHtml, "img") || strings.Contains(pHtml, "table") {
-	//		s.Remove()
-	//	}
-	//})
-	//if contentSub == "" || len(contentSub) < 200 {
-	//	//m := 0
-	//	doc.Find("span").Each(func(i int, s *goquery.Selection) {
-	//		spanHtml, _ := s.Html()
-	//		if strings.Contains(spanHtml, "img") || strings.Contains(spanHtml, "table") {
-	//			s.Remove()
-	//		}
-	//	})
-	//}
 	docText := doc.Text()
 	bodyRune := []rune(docText)
 	bodyRuneLen := len(bodyRune)