Remove redundant step numbers from recipe instructions in UI and database

This commit is contained in:
2026-10-17 17:08:07 +02:00
parent b86cbbeaa0
commit 814fd54d75
7 changed files with 129 additions and 2 deletions
+19
View File
@@ -85,6 +85,21 @@ def clean_source_label(source: Optional[str]) -> str:
return src
def clean_instructions_text(text: Optional[str]) -> str:
"""Entfernt vorangestellte Schrittnummern (z. B. '1. ', 'Schritt 1: ') aus Zubereitungszeilen."""
if not text:
return ""
import re
cleaned_lines = []
for line in str(text).splitlines():
line_s = line.strip()
if not line_s:
continue
cleaned = re.sub(r'^(?:Schritt\s*\d+[:.]?|\d+[\.\)\:])\s*', '', line_s, flags=re.IGNORECASE)
cleaned_lines.append(cleaned)
return "\n".join(cleaned_lines)
def guess_category_for_ingredient(name: str) -> str:
"""Bestimmt automatisch die passende Supermarkt-Kategorie anhand deutscher Zutaten-Keywords."""
if not name:
@@ -713,6 +728,8 @@ def add_recipe(
# Fallback to mapped chapter number if possible
chapter_number = CHAPTER_MAP.get(category, 1)
instructions = clean_instructions_text(instructions)
res = execute_query(
"""
INSERT INTO recipes (title, category, chapter_number, effort, prep_time, cook_time, portions, has_portion_table, ingredients, instructions, notes, source, image_url, printed_at)
@@ -755,6 +772,8 @@ def update_recipe(
if not existing:
raise KeyError(f"Rezept #{recipe_id} nicht gefunden.")
instructions = clean_instructions_text(instructions)
use_portion_table = int(bool(has_portion_table)) if has_portion_table is not None else existing.get("has_portion_table", 0)
if image_url is not None: