@@ -2,6 +2,7 @@ package service
22
33import (
44 "errors"
5+ "unicode/utf8"
56
67 "github.com/nk-akun/NeighborBBS/logs"
78 "github.com/nk-akun/NeighborBBS/model"
@@ -36,7 +37,7 @@ func (s *articleService) BuildArticle(userID int64, title string, content string
3637
3738func (s * articleService ) GetArticleList (limit int , cursorTime int64 , sortby string , order string ) (* model.ArticleListResponse , error ) {
3839 resp := & model.ArticleListResponse {}
39- fields := []string {"id" , "title" , "create_time" , "user_id" , "view_count" , "comment_count" , "like_count" }
40+ fields := []string {"id" , "title" , "create_time" , "user_id" , "view_count" , "comment_count" , "like_count" , "content" }
4041 articles := repository .ArticleRepository .GetArticleFields (util .DB (), fields , cursorTime , limit , sortby , order )
4142
4243 briefList , minCursorTime := buildArticleList (articles )
@@ -66,7 +67,7 @@ func (s *articleService) GetArticleByID(id int64) (*model.ArticleResponse, error
6667 ArticleID : articleInfo .ID ,
6768 Title : articleInfo .Title ,
6869 User : BuildUserBriefInfo (userInfo ),
69- Content : util .ToHTML (articleInfo .Content ),
70+ Content : util .MarkdownToHTML (articleInfo .Content ),
7071 CommentCount : articleInfo .CommentCount ,
7172 LikeCount : articleInfo .LikeCount ,
7273 CreateTime : articleInfo .CreateTime ,
@@ -79,9 +80,11 @@ func buildArticleList(articles []model.Article) ([]*model.ArticleBriefInfo, int6
7980 briefList := make ([]* model.ArticleBriefInfo , len (articles ))
8081 for i := range articles {
8182 minCursorTime = util .MinInt64 (minCursorTime , articles [i ].CreateTime )
83+ mkSummary := util .MarkdownToHTML (util .SubString (articles [i ].Content , 0 , util .MinInt (128 , utf8 .RuneCountInString (articles [i ].Content ))))
8284 briefList [i ] = new (model.ArticleBriefInfo )
8385 briefList [i ].ArticleID = articles [i ].ID
8486 briefList [i ].Title = articles [i ].Title
87+ briefList [i ].Summary = util .GetHTMLText (mkSummary )
8588 briefList [i ].CommentCount = articles [i ].CommentCount
8689 briefList [i ].LikeCount = articles [i ].LikeCount
8790 briefList [i ].ViewCount = articles [i ].ViewCount
0 commit comments