🐛 Fix count post content length

This commit is contained in:
LittleSheep 2024-11-25 00:33:57 +08:00
parent e906874b2e
commit 09335ea99f

View File

@ -477,11 +477,11 @@ func TruncatePostContent(post models.Post) models.Post {
if post.Body["content"] != nil { if post.Body["content"] != nil {
if val, ok := post.Body["content"].(string); ok { if val, ok := post.Body["content"].(string); ok {
length := TruncatePostContentThreshold length := TruncatePostContentThreshold
post.Body["content_length"] = len([]rune(val))
if len([]rune(val)) >= length { if len([]rune(val)) >= length {
post.Body["content"] = string([]rune(val)[:length]) + "..." post.Body["content"] = string([]rune(val)[:length]) + "..."
post.Body["content_truncated"] = true post.Body["content_truncated"] = true
} }
post.Body["content_length"] = len([]rune(val))
} }
} }