mirror of
https://github.com/perstarkse/minne.git
synced 2026-06-30 10:01:40 +02:00
chore: improve html-router auth, caching, and analytics while centralizing search labels in common.
small fix
This commit is contained in:
@@ -1,26 +1,14 @@
|
||||
use common::storage::types::text_content::TextContent;
|
||||
|
||||
use super::truncate::with_ellipsis;
|
||||
|
||||
const TEXT_PREVIEW_LENGTH: usize = 50;
|
||||
|
||||
fn maybe_truncate(value: &str) -> Option<String> {
|
||||
for (char_count, (idx, _)) in value.char_indices().enumerate() {
|
||||
if char_count == TEXT_PREVIEW_LENGTH {
|
||||
return Some(value[..idx].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn truncate_text_content(mut content: TextContent) -> TextContent {
|
||||
if let Some(truncated) = maybe_truncate(&content.text) {
|
||||
content.text = truncated;
|
||||
}
|
||||
content.text = with_ellipsis(&content.text, TEXT_PREVIEW_LENGTH);
|
||||
|
||||
if let Some(context) = content.context.as_mut() {
|
||||
if let Some(truncated) = maybe_truncate(context) {
|
||||
*context = truncated;
|
||||
}
|
||||
*context = with_ellipsis(context, TEXT_PREVIEW_LENGTH);
|
||||
}
|
||||
|
||||
content
|
||||
|
||||
Reference in New Issue
Block a user