🐛 Fix truncate content panic
This commit is contained in:
		@@ -475,10 +475,12 @@ 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 {
 | 
			
		||||
		if val, ok := post.Body["content"].(string); ok {
 | 
			
		||||
			length := TruncatePostContentThreshold
 | 
			
		||||
			post.Body["content"] = string([]rune(val)[:length]) + "..."
 | 
			
		||||
			post.Body["content_truncated"] = true
 | 
			
		||||
			if len([]rune(val)) >= length {
 | 
			
		||||
				post.Body["content"] = string([]rune(val)[:length]) + "..."
 | 
			
		||||
				post.Body["content_truncated"] = true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user