URLS en interfaz invisible

This commit is contained in:
Jesús Pavón Abián
2026-02-02 18:41:11 +01:00
parent aca1e07f84
commit 5abe9e7d74
4 changed files with 81 additions and 12 deletions

View File

@@ -76,6 +76,33 @@ def compose_post(post, db, settings, relative_times, show_screen_names=False, sa
else:
text = original_text
# Check facets for links not visible in text and append them
facets = g(record, "facets", []) or []
hidden_urls = []
for facet in facets:
features = g(facet, "features", []) or []
for feature in features:
ftype = g(feature, "$type") or g(feature, "py_type") or ""
if "link" in ftype.lower():
uri = g(feature, "uri", "")
if uri and uri not in text and uri not in hidden_urls:
# Check if a truncated version is in text (e.g., "example.com/path...")
# by checking if the domain is present
domain_match = False
try:
from urllib.parse import urlparse
parsed = urlparse(uri)
domain = parsed.netloc.replace("www.", "")
if domain and domain in text:
domain_match = True
except:
pass
if not domain_match:
hidden_urls.append(uri)
if hidden_urls:
text += " " + " ".join(f"[{url}]" for url in hidden_urls)
# Labels / Content Warning
labels = g(actual_post, "labels", [])
cw_text = ""
@@ -113,6 +140,11 @@ def compose_post(post, db, settings, relative_times, show_screen_names=False, sa
images = g(media, "images", [])
if images:
text += f" [{len(images)} {_('images')}]"
elif mtype and "external" in mtype:
ext = g(media, "external", {})
title = g(ext, "title", "")
if title:
text += f" [{_('Link')}: {title}]"
elif etype and ("record" in etype):
quote_rec = g(embed, "record", {})

View File

@@ -92,6 +92,34 @@ def process_date(field, relative_times=True, offset_hours=0):
return original_date.shift(hours=offset_hours).format(_("dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2])
def _extract_link_info(post, record):
"""Extract link information from post embeds and facets."""
embed = _g(post, "embed")
if not embed:
return None
etype = _g(embed, "$type") or _g(embed, "py_type") or ""
# Direct external embed
if "external" in etype.lower():
ext = _g(embed, "external", {})
title = _g(ext, "title", "")
if title:
return title
# RecordWithMedia with external
if "recordWithMedia" in etype:
media = _g(embed, "media", {})
mtype = _g(media, "$type") or _g(media, "py_type") or ""
if "external" in mtype.lower():
ext = _g(media, "external", {})
title = _g(ext, "title", "")
if title:
return title
return None
def render_post(post, template, settings, relative_times=False, offset_hours=0):
actual_post = _g(post, "post", post)
record = _g(actual_post, "record") or _g(post, "record") or {}
@@ -118,10 +146,19 @@ def render_post(post, template, settings, relative_times=False, offset_hours=0):
original_handle = _g(author, "handle", "")
text = _("Reposted from @{handle}: {text}").format(handle=original_handle, text=text)
# Add link indicator for external embeds
link_title = _extract_link_info(actual_post, record)
if link_title:
text += f" [{_('Link')}: {link_title}]"
cw_text = _extract_cw_text(actual_post, record)
safe_text = text
if cw_text:
safe_text = _("Content warning: {cw}").format(cw=cw_text)
# Include link info in safe_text even with content warning
if link_title:
safe_text = _("Content warning: {cw}").format(cw=cw_text) + f" [{_('Link')}: {link_title}]"
else:
safe_text = _("Content warning: {cw}").format(cw=cw_text)
created_at = _g(record, "createdAt") or _g(record, "created_at")
indexed_at = _g(actual_post, "indexedAt") or _g(actual_post, "indexed_at")

View File

@@ -237,12 +237,12 @@ def find_urls(post):
record = g(actual_post, "record", {})
# Check facets for link annotations
facets = g(record, "facets", [])
facets = g(record, "facets", []) or []
for facet in facets:
features = g(facet, "features", [])
features = g(facet, "features", []) or []
for feature in features:
ftype = g(feature, "$type") or g(feature, "py_type")
if ftype and "link" in ftype:
if ftype and "link" in ftype.lower():
uri = g(feature, "uri", "")
if uri and uri not in urls:
urls.append(uri)