1677e40668
Added a shared ExportMarkdownButton (copy to clipboard / download .md) next to every existing print button: recipe, shopping list, collection, meal plan, pantry. Each surface gets a small serializer in lib/markdown/ built from data already in scope at that page — no new queries except pantry, where items now thread through as a prop to PantryPageHeader instead of being fetched only for PantryManager. Also fixes an unrelated bug hit while verifying the collection export: RecipeCard called the client-only useTranslations() hook without "use client", so it rendered fine everywhere it happened to run inside an already-client tree but 500'd — "Couldn't find next-intl config file" — when Next tried to run it as a Server Component, which only happens on the collection detail page (its only caller). Collections with recipes in them were completely broken. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
932 B
TypeScript
34 lines
932 B
TypeScript
type MealPlanMarkdownInput = {
|
|
label: string;
|
|
entries: Array<{
|
|
day: string;
|
|
mealType: string;
|
|
servings: number;
|
|
note: string | null;
|
|
recipe: { title: string } | null;
|
|
}>;
|
|
};
|
|
|
|
export function mealPlanToMarkdown(plan: MealPlanMarkdownInput): string {
|
|
const lines: string[] = [`# Meal Plan — ${plan.label}`, ""];
|
|
|
|
const byDay = new Map<string, typeof plan.entries>();
|
|
for (const entry of plan.entries) {
|
|
const group = byDay.get(entry.day) ?? [];
|
|
group.push(entry);
|
|
byDay.set(entry.day, group);
|
|
}
|
|
|
|
for (const [day, entries] of byDay) {
|
|
lines.push(`## ${day}`, "");
|
|
for (const entry of entries) {
|
|
const title = entry.recipe?.title ?? "(no recipe)";
|
|
const note = entry.note ? ` — ${entry.note}` : "";
|
|
lines.push(`- **${entry.mealType}**: ${title} (${entry.servings} servings)${note}`);
|
|
}
|
|
lines.push("");
|
|
}
|
|
|
|
return lines.join("\n").trim() + "\n";
|
|
}
|