urlinfo:generic: improve output

This commit is contained in:
ducklet 2021-10-11 21:15:15 +02:00
parent 370ae8e19f
commit 9202bcbb77

View file

@ -39,12 +39,16 @@ def generic_details(info, url: str):
text = ""
if info.extracted.title:
text += f"<b>{info.extracted.title}</b> — "
text += f'<b><a href="{info.final_url}">{info.extracted.title}</a></b> — '
text += "; ".join(details)
return text
def ld_details(ex, tz, lc):
def ld_details(info, tz, lc):
escape_all(info)
ex = info.extracted.ld
url = info.final_url
details = []
if ex.creators:
details.append(f"🖋 {' '.join(ex.creators[:2])}")
@ -53,7 +57,7 @@ def ld_details(ex, tz, lc):
lines = []
if ex.title:
lines.append(f"<b>{ex.title}</b>")
lines.append(f'<b><a href="{url}">{ex.title}</a></b>')
if ex.published:
lines[
-1
@ -76,9 +80,7 @@ async def handle(message: Message, url, load_info):
roomconf = message.app.config.l6n[message.room.room_id]
plain = html = None
if info.extracted.ld and info.extracted.ld.description:
html, plain = ld_details(
info.extracted.ld, tz=roomconf["timezone"], lc=roomconf["locale"]
)
html, plain = ld_details(info, tz=roomconf["timezone"], lc=roomconf["locale"])
else:
html = generic_details(info, url)