feat: import 48 new recipes from weitere Rezepte with images and dynamic TOC pagination

This commit is contained in:
2026-10-16 21:45:59 +02:00
parent 0d61616396
commit 1d2e5570dc
39 changed files with 1732 additions and 67 deletions
+34 -21
View File
@@ -400,9 +400,28 @@ async def cookbook_view(
# --- Seitenzahlen & Inhaltsverzeichnis (TOC) berechnen ---
# Seite 1: Cover
# TOC: Bei einzeiligem Inhaltsverzeichnis (1 Spalte) passen ca. 26 Rezepte + Kapitelheader ideal auf 1 Seite
total_display_recipes = len(all_recipes)
toc_page_count = 2 if total_display_recipes > 26 else (1 if total_display_recipes > 0 else 0)
# TOC: Bei einzeiligem Inhaltsverzeichnis (1 Spalte) passen ca. 24-28 Einträge (Rezepte + Kapitelheader) ideal auf 1 A4-Seite
active_chapters = [c for c in chapters_to_display if recipes_by_chapter.get(c["number"])]
toc_pages_raw = []
cur_toc = []
cur_w = 0
MAX_TOC_PAGE_WEIGHT = 26
for c in active_chapters:
c_recs = recipes_by_chapter.get(c["number"], [])
item_w = len(c_recs) + 2
if cur_w + item_w > MAX_TOC_PAGE_WEIGHT and cur_toc:
toc_pages_raw.append(cur_toc)
cur_toc = [c]
cur_w = item_w
else:
cur_toc.append(c)
cur_w += item_w
if cur_toc:
toc_pages_raw.append(cur_toc)
toc_page_count = len(toc_pages_raw)
current_page = 1 + toc_page_count + 1
display_chapters_data = []
@@ -423,25 +442,18 @@ async def cookbook_view(
chap_copy["recipes"] = chap_recipes
display_chapters_data.append(chap_copy)
# Inhaltsverzeichnis aufteilen (falls 2 Seiten: gleichmäßige 50/50 Balance)
active_chapters = [c for c in display_chapters_data if recipes_by_chapter.get(c["number"], [])]
total_weight = sum(len(recipes_by_chapter.get(c["number"], [])) + 2 for c in active_chapters)
half_weight = total_weight / 2
# Inhaltsverzeichnis Seiten mit vollständigen Kapitel- & Rezeptdaten
display_by_number = {c["number"]: c for c in display_chapters_data}
toc_pages = []
for p_idx, p_chaps in enumerate(toc_pages_raw):
toc_pages.append({
"page_index": p_idx + 1,
"book_page": p_idx + 2,
"chapters": [display_by_number[c["number"]] for c in p_chaps if c["number"] in display_by_number]
})
toc_p1 = []
toc_p2 = []
if toc_page_count == 2:
accum = 0
for c in active_chapters:
c_recs = recipes_by_chapter.get(c["number"], [])
item_weight = len(c_recs) + 2
if accum < half_weight or not toc_p1:
toc_p1.append(c)
accum += item_weight
else:
toc_p2.append(c)
else:
toc_p1 = active_chapters
toc_p1 = toc_pages[0]["chapters"] if toc_pages else []
toc_p2 = toc_pages[1]["chapters"] if len(toc_pages) > 1 else []
# User Agent Check für Apple iOS
user_agent = request.headers.get("user-agent", "").lower()
@@ -457,6 +469,7 @@ async def cookbook_view(
"recipes_by_chapter": recipes_by_chapter,
"recipe_counts": recipe_counts,
"total_recipes": len(all_recipes),
"toc_pages": toc_pages,
"toc_page_count": toc_page_count,
"toc_p1": toc_p1,
"toc_p2": toc_p2,