Truncate too content when listing

This commit is contained in:
2024-10-13 20:12:23 +08:00
parent d6b6f2e399
commit d1bbf751d3
3 changed files with 61 additions and 0 deletions

View File

@ -470,3 +470,16 @@ func PinPost(post models.Post) (bool, error) {
}
return post.PinnedAt != nil, nil
}
const TruncatePostContentThreshold = 160
func TruncatePostContent(post models.Post) models.Post {
if post.Body["content"] != nil {
if val, ok := post.Body["content"].(string); ok && len(val) >= TruncatePostContentThreshold {
post.Body["content"] = val[:TruncatePostContentThreshold] + "..."
post.Body["content_truncated"] = true
}
}
return post
}