mirror of
https://framagit.org/veretcle/oolatoocs.git
synced 2025-07-20 20:41:17 +02:00
💄: better record link content
This commit is contained in:
12
src/bsky.rs
12
src/bsky.rs
@@ -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(),
|
||||
|
Reference in New Issue
Block a user