mirror of
https://github.com/go-gitea/gitea
synced 2025-07-27 04:38:36 +00:00
chore: simplify truncateContent
This commit is contained in:
@@ -221,13 +221,9 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func truncateContent(content string, n int) string {
|
func truncateContent(content string, n int) string {
|
||||||
truncatedContent, truncatedRight := util.SplitStringAtByteN(content, n)
|
truncated, omitted := util.SplitStringAtByteN(content, n)
|
||||||
if truncatedRight != "" {
|
if omitted != "" {
|
||||||
// in case the content is in a Latin family language, we remove the last broken word.
|
truncated += "…"
|
||||||
lastSpaceIdx := strings.LastIndex(truncatedContent, " ")
|
|
||||||
if lastSpaceIdx != -1 && (len(truncatedContent)-lastSpaceIdx < 15) {
|
|
||||||
truncatedContent = truncatedContent[:lastSpaceIdx] + "…"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return truncatedContent
|
return truncated
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user