From 6c25f141899179e83354067c95f198ff8d6ee1d0 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 13 Oct 2024 20:26:03 +0800 Subject: [PATCH] :bug: Fix truncate make utf8 word garbled --- pkg/internal/services/posts.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index af3b010..1bab196 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -476,7 +476,8 @@ 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] + "..." + length := TruncatePostContentThreshold + post.Body["content"] = string([]rune(val)[:length]) + "..." post.Body["content_truncated"] = true } }