1
0
mirror of https://gitlab.com/Anson-Projects/anson-stuff/zinetest.git synced 2025-06-15 21:46:40 +00:00

Update to support nonstandard characters

This commit is contained in:
Anson Biggs 2024-02-10 16:57:06 -07:00
parent 8ad3fecc39
commit 4d5cb275f8

View File

@ -72,7 +72,14 @@ fn create_html_card(entry: &Entry) -> Markup {
fn truncate_description(description: &str, max_length: usize) -> String { fn truncate_description(description: &str, max_length: usize) -> String {
let description_trimmed = description.trim(); let description_trimmed = description.trim();
if description_trimmed.len() > max_length { 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 { } else {
description_trimmed.to_string() description_trimmed.to_string()
} }