From 46bbe8639d062658b16b8f5cba6cf5ec15ba6878 Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 04:14:03 +0800 Subject: [PATCH] refactor(bsky): delegate the post caption to the shared builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Post::caption hand-formatted exactly the string site::caption produces — same template, same three escapes (the shared fn even handles the empty-text case these two lines did not: no dangling ': ' after the author link). One line now, matching what bilibili and misskey already do; the encode_double_quoted_attribute import loses its last bsky user. --- crates/x-media/src/site/bsky/interface.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/x-media/src/site/bsky/interface.rs b/crates/x-media/src/site/bsky/interface.rs index 8859f7d..87b302d 100644 --- a/crates/x-media/src/site/bsky/interface.rs +++ b/crates/x-media/src/site/bsky/interface.rs @@ -1,7 +1,7 @@ use super::model; use crate::media::Media; use crate::site::{FetchError, Fetched, Site, SiteFuture}; -use html_escape::{encode_double_quoted_attribute, encode_text}; +use html_escape::encode_text; use regex::Regex; use std::sync::LazyLock; @@ -330,13 +330,7 @@ impl Post { } 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) } pub fn from_json(raw_json: &str, id: String) -> Result { @@ -393,7 +387,6 @@ impl From for Fetched { let url = post.url(); let author_url = post.author_url(); let render_data = Some(crate::site::RenderData { - url: url.clone(), author: encode_text(&post.author).into_owned(), author_url: author_url.clone(), // A post has no title: its text is all content.