diff --git a/backend/src/quick-import/parsers/base.parser.ts b/backend/src/quick-import/parsers/base.parser.ts index b448e63f..e8b65e35 100644 --- a/backend/src/quick-import/parsers/base.parser.ts +++ b/backend/src/quick-import/parsers/base.parser.ts @@ -59,15 +59,25 @@ export abstract class RecipeParser { cleaned = cleaned.replace(/\s*\([^)]*\)/, '').trim(); } - // Hantera bråkdelar: "1/2" eller "1 / 2" - const fractionMatch = cleaned.match(/^([\d.]+)\s*\/\s*([\d.]+)/); + // Hantera bråkdelar: "1/2" eller "1 1/2" eller "1 1 / 2" + // Regex: (optional whole)? numerator / denominator + const fractionMatch = cleaned.match(/^(\d+)?\s*(\d+)\s*\/\s*([\d.]+)/); let quantity = 0; let remainingText = cleaned; if (fractionMatch) { - const numerator = parseFloat(fractionMatch[1]); - const denominator = parseFloat(fractionMatch[2]); - quantity = numerator / denominator; + if (fractionMatch[1]) { + // Heltal + bråk: "1 1/2" + const whole = parseFloat(fractionMatch[1]); + const numerator = parseFloat(fractionMatch[2]); + const denominator = parseFloat(fractionMatch[3]); + quantity = whole + (numerator / denominator); + } else { + // Bara bråk: "1/2" + const numerator = parseFloat(fractionMatch[2]); + const denominator = parseFloat(fractionMatch[3]); + quantity = numerator / denominator; + } remainingText = cleaned.substring(fractionMatch[0].length).trim(); } else { const numberMatch = remainingText.match(/^([\d.,]+)/); diff --git a/backend/src/quick-import/parsers/generic.parser.ts b/backend/src/quick-import/parsers/generic.parser.ts index 898ff28e..04d86b76 100644 --- a/backend/src/quick-import/parsers/generic.parser.ts +++ b/backend/src/quick-import/parsers/generic.parser.ts @@ -42,6 +42,7 @@ export class GenericRecipeParser extends RecipeParser { private extractFromJsonLd(recipe: any): ParsedRecipe { const name = recipe.name || ''; + const description = recipe.description || ''; const ingredients: Array<{ quantity: number; unit: string; name: string; note?: string }> = []; if (recipe.recipeIngredient && Array.isArray(recipe.recipeIngredient)) { @@ -71,6 +72,7 @@ export class GenericRecipeParser extends RecipeParser { return { name, + description, ingredients, instructions, }; @@ -90,6 +92,15 @@ export class GenericRecipeParser extends RecipeParser { name = titleMatch[1].trim(); } + // Försöka extrahera beskrivning från meta-taggar + let description = ''; + const descMatch = html.match( + / = []; @@ -129,6 +140,7 @@ export class GenericRecipeParser extends RecipeParser { return { name, + description, ingredients, instructions, }; diff --git a/backend/src/quick-import/parsers/ica.parser.ts b/backend/src/quick-import/parsers/ica.parser.ts index ae058194..361a710f 100644 --- a/backend/src/quick-import/parsers/ica.parser.ts +++ b/backend/src/quick-import/parsers/ica.parser.ts @@ -45,6 +45,9 @@ export class IcaRecipeParser extends RecipeParser { // Extrahera titel const name = recipe.name || ''; + // Extrahera beskrivning + const description = recipe.description || ''; + // Extrahera ingredienser const ingredients: Array<{ quantity: number; unit: string; name: string; note?: string }> = []; if (recipe.recipeIngredient && Array.isArray(recipe.recipeIngredient)) { @@ -75,6 +78,7 @@ export class IcaRecipeParser extends RecipeParser { return { name, + description, ingredients, instructions, }; @@ -96,6 +100,15 @@ export class IcaRecipeParser extends RecipeParser { } } + // Extrahera beskrivning från meta-taggar + let description = ''; + const descMatch = html.match( + / = []; const ingredientRegex = /
+ Inga ingredienser tolkades från Markdown-texten. +
+ )} +
{markdown}
-
{JSON.stringify(parsed, null, 2)}
- - Inga ingredienser tolkades från Markdown-texten. -
- )} -