pub(super) fn parse_text_fields(block: &str) -> (String, String, String) {
let (title, url) = parse_text_metadata(block);
let mut description = collect_description(block);
if description.chars().count() > 500 {
description = crate::common::text_slice::truncate_chars(&description, 500);
description.push_str("...");
}
(title, url, description)
}
fn parse_text_metadata(block: &str) -> (String, String) {
let mut title = String::new();
let mut url = String::new();
for line in block.lines() {
let line = line.trim();
if let Some(t) = line.strip_prefix("Title: ") {
title = t.trim().to_string();
} else if let Some(u) = line.strip_prefix("URL: ") {
url = u.trim().to_string();
}
}
(title, url)
}
fn is_description_line(line: &str) -> bool {
!line.starts_with("Title: ")
&& !line.starts_with("URL: ")
&& !line.starts_with("Highlights:")
&& !line.starts_with("Published:")
&& !line.starts_with("Author:")
&& !line.is_empty()
&& !line.starts_with("...")
}
fn collect_description(block: &str) -> String {
let mut description = String::new();
for line in block.lines() {
let line = line.trim();
if !is_description_line(line) {
continue;
}
if !description.is_empty() {
description.push(' ');
}
description.push_str(line);
}
description
}