fix comment render bug
This commit is contained in:
parent
eed45f51ba
commit
ceffeccf8d
@ -25,7 +25,6 @@ type Comments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CommentHtml interface {
|
type CommentHtml interface {
|
||||||
Sort(i, j *Comments) bool
|
|
||||||
FormatLi(c *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string
|
FormatLi(c *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +50,16 @@ func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, m
|
|||||||
|
|
||||||
func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html string) {
|
func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html string) {
|
||||||
s := str.NewBuilder()
|
s := str.NewBuilder()
|
||||||
if d.depth > d.maxDepth {
|
if d.depth >= d.maxDepth {
|
||||||
comments = d.findComments(comments)
|
comments = d.findComments(comments)
|
||||||
}
|
}
|
||||||
slice.Sort(comments, d.i.Sort)
|
order := wpconfig.GetOption("comment_order")
|
||||||
|
slice.Sort(comments, func(i, j *Comments) bool {
|
||||||
|
if order == "asc" {
|
||||||
|
return i.CommentDate.Sub(j.CommentDate) < 0
|
||||||
|
}
|
||||||
|
return i.CommentDate.Sub(j.CommentDate) > 0
|
||||||
|
})
|
||||||
for i, comment := range comments {
|
for i, comment := range comments {
|
||||||
eo := "even"
|
eo := "even"
|
||||||
if (i+1)%2 == 0 {
|
if (i+1)%2 == 0 {
|
||||||
@ -85,7 +90,7 @@ func (d CommentHandler) findComments(comments []*Comments) []*Comments {
|
|||||||
var r []*Comments
|
var r []*Comments
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
tmp := *comment
|
tmp := *comment
|
||||||
comment.Children = nil
|
tmp.Children = nil
|
||||||
r = append(r, &tmp)
|
r = append(r, &tmp)
|
||||||
if len(comment.Children) > 0 {
|
if len(comment.Children) > 0 {
|
||||||
t := d.findComments(comment.Children)
|
t := d.findComments(comment.Children)
|
||||||
@ -135,14 +140,6 @@ func CommentRender() CommonCommentFormat {
|
|||||||
type CommonCommentFormat struct {
|
type CommonCommentFormat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CommonCommentFormat) Sort(i, j *Comments) bool {
|
|
||||||
order := wpconfig.GetOption("comment_order")
|
|
||||||
if order == "asc" {
|
|
||||||
return i.CommentDate.UnixNano() < j.CommentDate.UnixNano()
|
|
||||||
}
|
|
||||||
return i.CommentDate.UnixNano() > j.CommentDate.UnixNano()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string {
|
func (c CommonCommentFormat) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls bool, eo, parent string) string {
|
||||||
return FormatLi(CommonLi(), ctx, m, depth, isTls, eo, parent)
|
return FormatLi(CommonLi(), ctx, m, depth, isTls, eo, parent)
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,8 @@ func CalComponents(h *Handle) {
|
|||||||
}
|
}
|
||||||
return t, true
|
return t, true
|
||||||
})
|
})
|
||||||
slice.Sort(r, func(i, j Components[string]) bool {
|
slice.SimpleSort(r, slice.DESC, func(t Components[string]) float64 {
|
||||||
return i.Order > j.Order
|
return t.Order
|
||||||
})
|
})
|
||||||
return r, true
|
return r, true
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user