💄: better record link content

This commit is contained in:
VC
2024-10-01 19:21:27 +02:00
parent ac8af5ce95
commit e0d3667fb9
3 changed files with 80 additions and 60 deletions

View File

@@ -32,11 +32,17 @@ pub async fn build_post_record(
) -> Result<RecordData, Box<dyn Error>> {
let mut rt = RichText::new_with_detect_facets(text).await?;
let re = Regex::new(r#"(https?://)(\S{1,29})(\S*)"#).unwrap();
let insert_chars = "";
let re = Regex::new(r#"(https?://)(\S{1,26})(\S*)"#).unwrap();
while let Some(found) = re.captures(&rt.text.clone()) {
if let Some(group) = found.get(3) {
rt.delete(group.start(), group.start() + group.len());
rt.insert(group.start(), insert_chars);
rt.delete(
group.start() + insert_chars.len(),
group.start() + insert_chars.len() + group.len(),
);
}
if let Some(group) = found.get(1) {
rt.delete(group.start(), group.start() + group.len());
@@ -190,7 +196,7 @@ mod tests {
#[tokio::test]
async fn test_build_post_record() {
let text = "@factornews@piaille.fr Retrouvez-nous ici https://www.nintendojo.fr/articles/editos/le-mod-renovation-de-8bitdo-pour-manette-n64 et là https://www.nintendojo.fr/articles/analyses/vite-vu/vite-vu-morbid-the-lords-of-ire";
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles/ed et là www.nintendojo.fr/articles/an";
let expected_text = "@factornews@piaille.fr Retrouvez-nous ici www.nintendojo.fr/articles et là www.nintendojo.fr/articles";
let bsky_conf = BlueskyConfig {
handle: "tamerelol.bsky.social".to_string(),