Remove redundant step numbers from recipe instructions in UI and database
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -130,6 +130,14 @@ async def auth_middleware(request: Request, call_next):
|
||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||
templates = Jinja2Templates(directory=TEMPLATES_DIR)
|
||||
|
||||
def strip_step_number_filter(text: str) -> str:
|
||||
if not text:
|
||||
return ""
|
||||
import re
|
||||
return re.sub(r'^(?:Schritt\s*\d+[:.]?|\d+[\.\)\:])\s*', '', str(text).strip(), flags=re.IGNORECASE)
|
||||
|
||||
templates.env.filters["strip_step_number"] = strip_step_number_filter
|
||||
|
||||
# Mapping Kochbuch-Kapitel -> Zufallsgenerator-Kategorien
|
||||
CHAPTER_TO_DISH_CAT = {
|
||||
"Suppen & Eintöpfe": "Suppen",
|
||||
|
||||
@@ -803,7 +803,7 @@
|
||||
{% if step.strip() %}
|
||||
<div class="step-card">
|
||||
<span class="step-badge">{{ loop.index }}</span>
|
||||
<div class="step-text">{{ step.strip() }}</div>
|
||||
<div class="step-text">{{ step.strip() | strip_step_number }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
@@ -181,7 +181,7 @@
|
||||
{% if step.strip() %}
|
||||
<div class="step-card">
|
||||
<span class="step-badge">{{ loop.index }}</span>
|
||||
<div class="step-text">{{ step.strip() }}</div>
|
||||
<div class="step-text">{{ step.strip() | strip_step_number }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user