1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-04-08 17:05:45 +02:00

chore: simplify truncateContent

This commit is contained in:
Jason Song 2023-01-05 15:16:14 +08:00
parent 4bb8604180
commit 08383bdcbc
No known key found for this signature in database
GPG Key ID: 8402EEEE4511A8B5

@ -221,13 +221,9 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
}
func truncateContent(content string, n int) string {
truncatedContent, truncatedRight := util.SplitStringAtByteN(content, n)
if truncatedRight != "" {
// in case the content is in a Latin family language, we remove the last broken word.
lastSpaceIdx := strings.LastIndex(truncatedContent, " ")
if lastSpaceIdx != -1 && (len(truncatedContent)-lastSpaceIdx < 15) {
truncatedContent = truncatedContent[:lastSpaceIdx] + "…"
}
truncated, omitted := util.SplitStringAtByteN(content, n)
if omitted != "" {
truncated += "…"
}
return truncatedContent
return truncated
}