|
@@ -13,6 +13,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+ "unicode/utf8"
|
|
|
)
|
|
|
|
|
|
func GetReportContentSub(content string) (contentSub string, err error) {
|
|
@@ -57,16 +58,48 @@ func GetReportContentTextSub(content string) (contentSub string, err error) {
|
|
|
|
|
|
func GetReportContentTextSubNew(content string) (contentSub string, err error) {
|
|
|
content = html.UnescapeString(content)
|
|
|
- doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
|
|
|
+ doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
|
|
|
+ if errdoc != nil {
|
|
|
+ err = errdoc
|
|
|
+ return
|
|
|
+ }
|
|
|
docText := doc.Text()
|
|
|
bodyRune := []rune(docText)
|
|
|
bodyRuneLen := len(bodyRune)
|
|
|
body := string(bodyRune[:bodyRuneLen])
|
|
|
contentSub = body
|
|
|
contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
|
|
|
+ contentSub = strings.Replace(body, " ", "", -1)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+//GetReportContentTextSubByarticle 解析文章内容
|
|
|
+func GetReportContentTextSubByarticle(content, abstract string, articleId int) (contentSub string, err error) {
|
|
|
+ var lenabstract int
|
|
|
+ //如果不是研选就这么展示
|
|
|
+ if articleId < utils.SummaryArticleId {
|
|
|
+ abstract = html.UnescapeString(abstract)
|
|
|
+ doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(abstract))
|
|
|
+ if errdoc != nil {
|
|
|
+ err = errdoc
|
|
|
+ return
|
|
|
+ }
|
|
|
+ docabstract := doc.Text()
|
|
|
+ lenabstract = utf8.RuneCountInString(docabstract)
|
|
|
+ if lenabstract >= 20 {
|
|
|
+ contentSub = docabstract
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ contentSub, err = GetReportContentTextSubNew(content)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ contentSub, err = GetReportContentTextSubNew(content)
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
//解析文章内容
|
|
|
func GetArticleAll() {
|
|
|
var err error
|