fix(rss): avoid truncated title+url post variants that create ellipsis posts

This commit is contained in:
2026-04-10 09:35:27 +02:00
parent 0d41c48b7a
commit 28dfe6d718

View File

@@ -41,7 +41,6 @@ BSKY_BLOB_TRANSIENT_ERROR_DELAY = 15
HTTP_TIMEOUT = 20
POST_RETRY_DELAY_SECONDS = 2
# Thumbnail upload cooldown state
THUMB_UPLOAD_COOLDOWN_UNTIL = 0
# --- Logging ---
@@ -137,9 +136,13 @@ def build_post_text_variants(title_text, link):
Preferred:
1. Full title + blank line + real URL
Fallbacks:
2. Truncated title + blank line + real URL
3. Full title only
4. Truncated title only
2. Full title only
3. Truncated title only
Intentionally avoid:
- truncated title + URL
That pattern creates ugly posts with "..." before the visible link.
"""
title_text = clean_whitespace(title_text)
link = canonicalize_url(link) or link or ""
@@ -156,24 +159,11 @@ def build_post_text_variants(title_text, link):
if title_text and link:
add_variant(f"{title_text}\n\n{link}")
reserve = len(link) + 2
available = BSKY_TEXT_MAX_LENGTH - reserve
if available > 10:
trimmed_title = title_text
if len(trimmed_title) > available:
trimmed_title = trimmed_title[:available - 3]
last_space = trimmed_title.rfind(" ")
if last_space > 0:
trimmed_title = trimmed_title[:last_space] + "..."
else:
trimmed_title = trimmed_title + "..."
add_variant(f"{trimmed_title}\n\n{link}")
if title_text:
add_variant(title_text)
add_variant(truncate_text_safely(title_text))
if link:
if link and not title_text:
add_variant(link)
return variants