From 4d5cb275f8acfc235a069f7c75db239c7c8f4bcb Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Sat, 10 Feb 2024 16:57:06 -0700 Subject: [PATCH] Update to support nonstandard characters --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4d4563f..74b28ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,14 @@ fn create_html_card(entry: &Entry) -> Markup { fn truncate_description(description: &str, max_length: usize) -> String { let description_trimmed = description.trim(); if description_trimmed.len() > max_length { - format!("{}...", &description_trimmed[..max_length]) + let mut char_boundary = max_length; + for (idx, _) in description_trimmed.char_indices() { + if idx > max_length { + break; + } + char_boundary = idx; + } + format!("{}...", &description_trimmed[..char_boundary]) } else { description_trimmed.to_string() }