mirror of
https://github.com/4cuck/teapawt.git
synced 2026-10-27 19:04:35 +00:00
embed: add view count, theme-color, and author avatar to Discord embeds
This commit is contained in:
1 parent
5b74d101d3
commit
e38d0e8bda
2 files changed
+18
-1
No files matched your search
@@ -360,7 +360,12 @@ pub const fn scale_dimensions_for_embed(width: i32, height: i32) -> (i32, i32) {
|
||||
}
|
||||
|
||||
/// Format engagement metrics for oEmbed `author_name` field.
|
||||
pub fn format_engagement_text(likes: i64, retweets: i64, replies: i64) -> String {
|
||||
pub fn format_engagement_text(
|
||||
likes: i64,
|
||||
retweets: i64,
|
||||
replies: i64,
|
||||
views: i64,
|
||||
) -> String {
|
||||
let mut parts = Vec::new();
|
||||
if likes > 0 {
|
||||
parts.push(format!("\u{2764} {}", format_with_commas(likes)));
|
||||
@@ -371,6 +376,9 @@ pub fn format_engagement_text(likes: i64, retweets: i64, replies: i64) -> String
|
||||
if replies > 0 {
|
||||
parts.push(format!("\u{1F4AC} {}", format_with_commas(replies)));
|
||||
}
|
||||
if views > 0 {
|
||||
parts.push(format!("\u{1F441} {}", format_with_commas(views)));
|
||||
}
|
||||
if parts.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
|
||||
@@ -246,6 +246,7 @@ fn build_oembed_url(tweet: &Tweet, url_prefix: &str) -> String {
|
||||
tweet.stats.likes,
|
||||
tweet.stats.retweets,
|
||||
tweet.stats.replies,
|
||||
tweet.stats.views,
|
||||
);
|
||||
format!(
|
||||
"{url_prefix}/owoembed?text={}&author={}&status={}",
|
||||
@@ -511,7 +512,15 @@ pub fn render_status_page(
|
||||
let canonical = format!("https://x.com/{username}/status/{id}");
|
||||
let referer = format!("/{username}/status/{id}");
|
||||
|
||||
let avatar_url = formatters::get_pic_url(&tweet.user.user_pic, config.config.base64_media);
|
||||
|
||||
let head_extra = html! {
|
||||
// Theme color for Discord embed accent
|
||||
meta name="theme-color" content="#1F1F1F";
|
||||
|
||||
// Profile pic as author icon in Discord embeds
|
||||
link rel="apple-touch-icon" href=(format!("{url_prefix}{avatar_url}"));
|
||||
|
||||
// Override OG title/description with tweet-specific values
|
||||
meta property="og:title" content=(og_title);
|
||||
meta property="og:description" content=(description);
|
||||
|
||||
Reference in new issue
Block a user