Przeglądaj źródła

首图标签转义符解析处理

xingzai 3 lat temu
rodzic
commit
2b2368c339
1 zmienionych plików z 10 dodań i 15 usunięć
  1. 10 15
      controllers/home.go

+ 10 - 15
controllers/home.go

@@ -1,7 +1,6 @@
 package controllers
 
 import (
-	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
@@ -112,23 +111,19 @@ func (this *HomeController) ListHome() {
 		item := list[i]
 		//如果文章一开始的内容是图片,优先展示第一张图片
 		imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[i].Body))
-		fmt.Println(list[i].Body)
 		newBody, _ := services.GetReportContentTextSub(item.Body)
 		list[i].Body = newBody
-		if len(newBody) > 0 {
-			strnum := strings.Index((list[i].Body), imgurl)
-			newBody = newBody[0:3]
-
-			strnum2 := strings.Index((list[i].Body), newBody)
-			fmt.Println(imgurl)
-			fmt.Println(newBody)
-			fmt.Println(strnum)
-			fmt.Println(strnum2)
-			if strnum < strnum2 {
-				list[i].BodyHtml = `<p>< img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
+		if imgurl != "" {
+			if len(newBody) > 0 {
+				strnum := strings.Index((list[i].Body), imgurl)
+				newBody = newBody[0:3]
+				strnum2 := strings.Index((list[i].Body), newBody)
+				if strnum < strnum2 {
+					list[i].BodyHtml = `<p><img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
+				}
+			} else {
+				list[i].BodyHtml = `<p><img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
 			}
-		} else {
-			list[i].BodyHtml = `<p>< img src="` + imgurl + `" class="fr-fic fr-dib"></p>`
 		}
 		list[i].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
 		if strings.Contains(item.CategoryName, "研选") {