From 3ea2478512f05228c384667a435bf45054196c72 Mon Sep 17 00:00:00 2001 From: VC Date: Thu, 12 Jun 2025 14:37:02 +0200 Subject: [PATCH] fix: count 26 chars per url each time --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/utils.rs | 14 ++++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82b6803..80028ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1806,7 +1806,7 @@ checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "oolatoocs" -version = "4.2.0" +version = "4.2.1" dependencies = [ "atrium-api", "bsky-sdk", diff --git a/Cargo.toml b/Cargo.toml index b60b05c..1282974 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "oolatoocs" -version = "4.2.0" +version = "4.2.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/utils.rs b/src/utils.rs index e5e0266..0d35d0e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -38,7 +38,13 @@ fn twitter_count(content: &str) -> usize { for word in split_content { if word.starts_with("http://") || word.starts_with("https://") { - count += 23; + // It’s not that simple. Bsky adapts itself to the URL. + // https://github.com -> 10 chars + // https://github.com/ -> 10 chars + // https://github.com/NVNTLabs -> 19 chars + // https://github.com/NVNTLabs/ -> 20 chars + // so taking the maximum here to simplify things + count += 26; } else { count += word.chars().count(); } @@ -100,11 +106,11 @@ mod tests { let content = "Shoot out to https://y.ml/ !"; - assert_eq!(twitter_count(content), 38); + assert_eq!(twitter_count(content), 41); let content = "this is the link https://www.google.com/tamerelol/youpi/tonperemdr/tarace.html if you like! What if I shit a final"; - assert_eq!(twitter_count(content), 76); + assert_eq!(twitter_count(content), 79); let content = "multi ple space"; @@ -112,7 +118,7 @@ mod tests { let content = "This link is LEEEEET\n\nhttps://www.factornews.com/actualites/ca-sent-le-sapin-pour-free-radical-design-49985.html"; - assert_eq!(twitter_count(content), 45); + assert_eq!(twitter_count(content), 48); } #[test]