readysite / website / internal / helpers / string.go
407 B
string.go
// Package helpers provides utility functions.
package helpers

import "unicode/utf8"

// TruncateTitle safely truncates a string to maxLen runes, adding "..." if truncated.
// Safe for multi-byte UTF-8 characters (emoji, accents, etc.).
func TruncateTitle(s string, maxLen int) string {
	if utf8.RuneCountInString(s) <= maxLen {
		return s
	}
	runes := []rune(s)
	return string(runes[:maxLen-3]) + "..."
}
← Back