From ee08cb0c29b707867935f7a87115520d11fa6a8d Mon Sep 17 00:00:00 2001 From: Dotty Dotter Date: Fri, 10 Apr 2026 18:40:13 +0200 Subject: [PATCH] Quellen-Seite: PDF-Thumbnails der ersten Seite + Thumbnail-API-Endpoint --- app/main.py | 31 +++++++++++++++++++++++++++++++ app/templates/quellen.html | 24 +++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 21d9b04..6c0a330 100644 --- a/app/main.py +++ b/app/main.py @@ -875,6 +875,37 @@ neu analysiert, um verifizierte Zitate zu erzeugen.

) +@app.get("/api/programme/thumbnail/{programm_id}") +async def programme_thumbnail(programm_id: str): + """Thumbnail der ersten Seite eines Wahlprogramm-PDFs (PNG, 200px breit). + + Wird auf der Quellen-Seite als Vorschau angezeigt. Cached 24h. + """ + import fitz + if programm_id not in PROGRAMME: + raise HTTPException(status_code=404) + info = PROGRAMME[programm_id] + pdf_path = static_dir / "referenzen" / info["pdf"] + if not pdf_path.exists(): + raise HTTPException(status_code=404) + try: + doc = fitz.open(str(pdf_path)) + page = doc[0] + # 200px Breite, proportional skaliert + zoom = 200 / page.rect.width + mat = fitz.Matrix(zoom, zoom) + pix = page.get_pixmap(matrix=mat) + png_bytes = pix.tobytes("png") + doc.close() + return Response( + content=png_bytes, + media_type="image/png", + headers={"Cache-Control": "public, max-age=86400"}, + ) + except Exception: + raise HTTPException(status_code=500) + + @app.get("/api/programme") async def list_programme(): """List all available programmes.""" diff --git a/app/templates/quellen.html b/app/templates/quellen.html index 7df3ccb..cb446d6 100644 --- a/app/templates/quellen.html +++ b/app/templates/quellen.html @@ -221,7 +221,13 @@

Wahlprogramme NRW 2022

{% for prog in programmes if prog.typ == 'wahlprogramm' %} -
+
+ + {{ prog.name }} + +

{{ prog.partei }} {{ prog.name }} @@ -230,7 +236,7 @@ Wahlprogramm {% if prog.bundesland %}{{ prog.bundesland }}{% endif %}

-
+
📄 PDF herunterladen @@ -240,14 +246,21 @@ {% endfor %}
+
{% endfor %}
- +

Grundsatzprogramme

{% for prog in programmes if prog.typ == 'parteiprogramm' %} -
+
+ + {{ prog.name }} + +

{{ prog.partei }} {{ prog.name }} @@ -255,7 +268,7 @@
Grundsatzprogramm
-
+
📄 PDF herunterladen @@ -265,6 +278,7 @@ {% endfor %}
+

{% endfor %}