diff --git a/src/lib/server/db/migrations/012_ingredient_section.sql b/src/lib/server/db/migrations/012_ingredient_section.sql new file mode 100644 index 0000000..deb1568 --- /dev/null +++ b/src/lib/server/db/migrations/012_ingredient_section.sql @@ -0,0 +1,4 @@ +-- Nullable -- old rows keep NULL, new rows may have a section heading. +-- Rendering rule: if section_heading is set (not NULL and not empty), +-- a new section with this title starts at this ingredient row. +ALTER TABLE ingredient ADD COLUMN section_heading TEXT; diff --git a/src/lib/server/parsers/ingredient.ts b/src/lib/server/parsers/ingredient.ts index 51230fc..8d28b83 100644 --- a/src/lib/server/parsers/ingredient.ts +++ b/src/lib/server/parsers/ingredient.ts @@ -105,16 +105,16 @@ export function parseIngredient(raw: string, position = 0): Ingredient { if (tail.length > 0) { const quantity = clampQuantity(UNICODE_FRACTION_MAP[firstChar]); const { unit, name } = splitUnitAndName(tail); - return { position, quantity, unit, name, note, raw_text: rawText }; + return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null }; } } const qtyPattern = /^((?:\d+[.,]?\d*(?:\s*[-–]\s*\d+[.,]?\d*)?)|(?:\d+\/\d+))\s+(.+)$/; const qtyMatch = qtyPattern.exec(working); if (!qtyMatch) { - return { position, quantity: null, unit: null, name: working, note, raw_text: rawText }; + return { position, quantity: null, unit: null, name: working, note, raw_text: rawText, section_heading: null }; } const quantity = clampQuantity(parseQuantity(qtyMatch[1])); const { unit, name } = splitUnitAndName(qtyMatch[2]); - return { position, quantity, unit, name, note, raw_text: rawText }; + return { position, quantity, unit, name, note, raw_text: rawText, section_heading: null }; } diff --git a/src/lib/types.ts b/src/lib/types.ts index c2d63d2..4be0532 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -5,6 +5,7 @@ export type Ingredient = { name: string; note: string | null; raw_text: string; + section_heading: string | null; }; export type Step = {