From 9fc55336760c57de3380bf89a2ea89f7645c1f55 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 04:15:11 +0800 Subject: [PATCH] refactor(twitter): delegate the tweet caption to the shared builder Tweet::caption duplicated site::caption byte for byte for non-empty text (and dropped the shared empty-text rule, leaving a dangling ': ' behind the author link when a tweet's text comes out empty after link expansion). It delegates now, like bsky's Post::caption a commit earlier and bilibili/misskey before them; encode_double_quoted_attribute loses its last twitter user. --- crates/x-media/src/site/twitter/interface.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/x-media/src/site/twitter/interface.rs b/crates/x-media/src/site/twitter/interface.rs index d870c02..1502983 100644 --- a/crates/x-media/src/site/twitter/interface.rs +++ b/crates/x-media/src/site/twitter/interface.rs @@ -1,7 +1,7 @@ use super::model; use crate::media::Media; use crate::site::{FetchError, Fetched, Site, SiteFuture}; -use html_escape::{decode_html_entities, encode_double_quoted_attribute, encode_text}; +use html_escape::{decode_html_entities, encode_text}; use regex::Regex; use std::sync::LazyLock; @@ -199,13 +199,7 @@ impl Tweet { } pub fn caption(&self) -> String { - format!( - "{url}\n{author}: {text}", - url = encode_double_quoted_attribute(&self.url()), - author_url = encode_double_quoted_attribute(&self.author_url()), - author = encode_text(&self.author), - text = encode_text(&self.text), - ) + crate::site::caption(&self.url(), &self.author_url(), &self.author, &self.text) } /// Builds a tweet from an already-parsed syndication body. Takes the value @@ -332,7 +326,6 @@ impl From for Fetched { let author_url = tweet.author_url(); // A tweet has no title: its text is all content. let render_data = Some(crate::site::RenderData { - url: url.clone(), author: encode_text(&tweet.author).into_owned(), author_url: author_url.clone(), title: String::new(),