feat: append source domain fragment to alert short URLs

Short URLs now include the original source domain as a URL fragment,
e.g. https://paste.mymx.me/s/foo#github.com, so the destination is
visible before clicking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-19 18:33:13 +01:00
parent 8ce6922cc3
commit 0c18ba8e3a

View File

@@ -12,6 +12,7 @@ import urllib.request
from datetime import datetime, timezone
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import urlparse
from derp.http import urlopen as _urlopen
from derp.plugin import command, event
@@ -1909,7 +1910,8 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None:
None, fp.shorten_url, bot, url,
)
if short_url != url:
display_url = short_url
domain = urlparse(url).hostname or ""
display_url = f"{short_url}#{domain}" if domain else short_url
else:
short_url = ""
except Exception:
@@ -2104,14 +2106,17 @@ async def cmd_alert(bot, message):
title = _truncate(title) if title else "(no title)"
if extra:
title = f"{title} | {extra}"
display_url = short_url or url
domain = urlparse(url).hostname or "" if url else ""
display_url = (f"{short_url}#{domain}" if short_url and domain
else short_url or url)
if fp and url and not short_url:
try:
new_short = await loop.run_in_executor(
None, fp.shorten_url, bot, url,
)
if new_short != url:
display_url = new_short
display_url = (f"{new_short}#{domain}" if domain
else new_short)
db.execute(
"UPDATE results SET short_url = ? WHERE id = ?",
(new_short, row_id),