Răsfoiți Sursa

研选核心观点处理

xingzai 2 ani în urmă
părinte
comite
92bddbcb0e
1 a modificat fișierele cu 48 adăugiri și 0 ștergeri
  1. 48 0
      services/article.go

+ 48 - 0
services/article.go

@@ -11,6 +11,7 @@ import (
 	"hongze/hongze_cygx/utils"
 	"html"
 	"net/url"
+	"regexp"
 	"sort"
 	"strconv"
 	"strings"
@@ -1802,6 +1803,10 @@ func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeA
 
 //处理核心观点的展示规则
 func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
+
+	if item.ArticleId >= utils.SummaryArticleId {
+		item.Annotation = YxArticleAnnotation(item)
+	}
 	if item.Annotation != "" {
 		annotation = strings.Replace(item.Annotation, "<br>", "", -1)
 	} else {
@@ -1852,3 +1857,46 @@ func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
 	}
 	return
 }
+
+//解析研选内容中的核心观点
+func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
+	body := strings.ReplaceAll(article.Body, "<strong>", "")
+	body = strings.ReplaceAll(body, "</strong>", "")
+	body = strings.ReplaceAll(body, "</ol>", "</div>")
+	body = strings.ReplaceAll(body, "<ol>", "<div>")
+	body = strings.ReplaceAll(body, "</li>", "</p>")
+	body = strings.ReplaceAll(body, "<li>", "<p>")
+	re, _ := regexp.Compile("<strong.*?>")
+	body = re.ReplaceAllString(body, "")
+	reLi, _ := regexp.Compile("<li.*?>")
+	body = reLi.ReplaceAllString(body, "")
+	var plus int
+	coreIndex := strings.Index(body, "核心观点:")
+	plus = 15
+	if coreIndex == -1 {
+		coreIndex = strings.Index(body, "核心观点:")
+		plus = 13
+	}
+	if coreIndex == -1 {
+		coreIndex = strings.Index(body, "核心观点")
+		plus = 12
+	}
+	if coreIndex == -1 {
+		coreIndex = strings.Index(body, "核心结论:")
+		plus = 15
+	}
+	if coreIndex == -1 {
+		coreIndex = strings.Index(body, "核心结论:")
+		plus = 13
+	}
+	if coreIndex == -1 {
+		coreIndex = strings.Index(body, "核心结论")
+		plus = 12
+	}
+	endIndex := strings.Index(body, "<hr")
+	if coreIndex != -1 && endIndex != -1 {
+		body = body[coreIndex+plus : endIndex]
+	}
+	annotation = body
+	return
+}