type RecipeMarkdownInput = { title: string; description: string | null; baseServings: number; prepMins: number | null; cookMins: number | null; difficulty: "easy" | "medium" | "hard" | null; sourceUrl: string | null; ingredients: Array<{ rawName: string; quantity: string | null; unit: string | null; note: string | null }>; steps: Array<{ instruction: string; timerSeconds: number | null }>; }; function formatQuantity(quantity: string | null, unit: string | null): string { return [quantity, unit].filter(Boolean).join(" "); } export function recipeToMarkdown(recipe: RecipeMarkdownInput): string { const lines: string[] = [`# ${recipe.title}`, ""]; if (recipe.description) { lines.push(recipe.description, ""); } const meta: string[] = [`Servings: ${recipe.baseServings}`]; if (recipe.prepMins) meta.push(`Prep: ${recipe.prepMins} min`); if (recipe.cookMins) meta.push(`Cook: ${recipe.cookMins} min`); if (recipe.difficulty) meta.push(`Difficulty: ${recipe.difficulty}`); lines.push(meta.join(" ยท "), ""); if (recipe.ingredients.length > 0) { lines.push("## Ingredients", ""); for (const ing of recipe.ingredients) { const qty = formatQuantity(ing.quantity, ing.unit); const note = ing.note ? ` (${ing.note})` : ""; lines.push(`- ${qty ? `${qty} ` : ""}${ing.rawName}${note}`); } lines.push(""); } if (recipe.steps.length > 0) { lines.push("## Instructions", ""); recipe.steps.forEach((step, i) => { const timer = step.timerSeconds ? ` (${Math.round(step.timerSeconds / 60)} min)` : ""; lines.push(`${i + 1}. ${step.instruction}${timer}`); }); lines.push(""); } if (recipe.sourceUrl) { lines.push(`Source: ${recipe.sourceUrl}`); } return lines.join("\n").trim() + "\n"; }