|
@@ -11,6 +11,7 @@ import (
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
"html"
|
|
|
"net/url"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -1708,13 +1709,6 @@ func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeA
|
|
|
list[k].BodyHtml = imgurl
|
|
|
}
|
|
|
}
|
|
|
- list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
|
|
|
- if strings.Contains(item.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) {
|
|
|
- list[k].IsResearch = true
|
|
|
- }
|
|
|
- if item.Pv > 999 {
|
|
|
- list[k].Pv = 999
|
|
|
- }
|
|
|
//如果文章一开始的内容是图片,优先展示第一张图片
|
|
|
//newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
|
|
|
list[k].Annotation = ArticleAnnotation(item)
|
|
@@ -1812,5 +1806,39 @@ func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
|
|
|
} else {
|
|
|
annotation = item.Abstract
|
|
|
}
|
|
|
+ if annotation != "" {
|
|
|
+ annotation = html.UnescapeString(annotation)
|
|
|
+ doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
|
|
|
+ docText := doc.Text()
|
|
|
+ mapDoc := make(map[int]string)
|
|
|
+ var mapSort []int
|
|
|
+ p := doc.Find("p")
|
|
|
+ p.Each(func(tk int, pd *goquery.Selection) {
|
|
|
+ pdText := pd.Text()
|
|
|
+ textLen := strings.Index(docText, pdText)
|
|
|
+ mapDoc[(strings.Index(docText, pdText))] = pdText
|
|
|
+ mapSort = append(mapSort, textLen)
|
|
|
+ })
|
|
|
+ li := doc.Find("li")
|
|
|
+ li.Each(func(tk int, li *goquery.Selection) {
|
|
|
+ liText := li.Text()
|
|
|
+ textLen := strings.Index(docText, liText)
|
|
|
+ mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
|
|
|
+ mapSort = append(mapSort, textLen)
|
|
|
+ })
|
|
|
+ //排序
|
|
|
+ sort.Ints(mapSort)
|
|
|
+ var annotationHtml string
|
|
|
+ for _, vSort := range mapSort {
|
|
|
+ for k, v := range mapDoc {
|
|
|
+ if k == vSort {
|
|
|
+ annotationHtml += v + "<br>"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ annotationHtml = strings.TrimRight(annotationHtml, "<br>")
|
|
|
+ annotationHtml = "<p>" + annotationHtml + "</p>"
|
|
|
+ annotation = annotationHtml
|
|
|
+ }
|
|
|
return
|
|
|
}
|