From fdfddf8ccf6d0813b12eeae606fbf84ae1dc7e49 Mon Sep 17 00:00:00 2001 From: Erik Thiele Date: Mon, 20 Jul 2026 15:34:27 +0200 Subject: [PATCH] Restyle link cards as a uniform tile grid Cards previously had ragged heights because summaries vary in length. Follow the community-scripts.org card pattern instead: fixed-height title and summary blocks (clamped to 2 and 3 lines with an ellipsis), a colored letter avatar derived from the domain, category and manufacturer as badges in the header, tags in a single clipped row, and domain plus added-date in a footer. The avatar color is derived locally from the domain, so no external favicon requests are made. Co-Authored-By: Claude Sonnet 5 --- app/main.py | 14 +++++++ app/templates/_link_card.html | 72 ++++++++++++++++++----------------- app/templates/base.html | 53 +++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 36 deletions(-) diff --git a/app/main.py b/app/main.py index 2763f9d..28f8231 100644 --- a/app/main.py +++ b/app/main.py @@ -1,6 +1,7 @@ import json from datetime import datetime, timezone from pathlib import Path +from urllib.parse import urlparse from fastapi import Depends, FastAPI, Form, Request from fastapi.responses import HTMLResponse, RedirectResponse, Response @@ -36,7 +37,20 @@ def format_datum(value: datetime | None) -> str: return value.astimezone().strftime("%d.%m.%Y, %H:%M") +def domain_of(url: str) -> str: + """Hostname ohne 'www.' – dient als Kürzel/Beschriftung der Karten.""" + host = urlparse(url or "").hostname or "" + return host[4:] if host.startswith("www.") else host + + +def avatar_hue(url: str) -> int: + """Stabile Farbe pro Domain, damit Karten wiedererkennbar sind.""" + return sum(ord(c) for c in domain_of(url)) % 360 + + templates.env.filters["datum"] = format_datum +templates.env.filters["domain"] = domain_of +templates.env.filters["hue"] = avatar_hue # --------------------------------------------------------------------------- diff --git a/app/templates/_link_card.html b/app/templates/_link_card.html index 73ba02c..2311ddf 100644 --- a/app/templates/_link_card.html +++ b/app/templates/_link_card.html @@ -1,22 +1,25 @@