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