Skip to content

feat(ui): meal plans laid out as a calendar - #596

Merged
LeMyst merged 4 commits into
cooklang:mainfrom
LeMyst:feat/meal-planner
Oct 4, 2026
Merged

LeMyst merged 4 commits into
cooklang:mainfrom
LeMyst:feat/meal-planner

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #385 (step 1 of the proposal).

A meal plan is any .menu with sections on two days or more. Nothing else marks it: the dates already in its section names are what the shopping list, the Today's menu banner, cook shopping-list and other Cooklang apps read, so the spec does not change (an earlier version of this PR used a plan: frontmatter block; it was dropped after review, see dd68344):

---
title: October fortnight
servings: 2
---

== Wednesday (2026-10-07) ==

Breakfast: \
- 

Dinner: \
- @./Risotto{2%servings}

= 2026-10-08 Dinner

- @./Soup{}

What changes

  • New Meal Plan, beside New Menu on the recipe list (/new?kind=plan): name, first day (Today / This week / Next week shortcuts), number of days (2–62, 1 week / 2 weeks shortcuts), meals, servings, and a preview of the dates covered. The file gets a section a day with an empty bullet under each meal, ready for the editor. Day and meal names are written in the page's language, like the editor toolbar. An error (bad date, taken name…) sends the form back with every choice kept.
  • The menu page shows a plan as a calendar: one card a day from the first dated day to the last, in weekday columns from md up (Sunday first for en-US and ja-JP, Monday otherwise), stacked on a phone. A day with no section still gets a card; a week with none is left out. Every day has a slot for each meal the plan's days name (Breakfast:), in the order they first appear, even when empty (—, "Nothing planned" for screen readers). Recipes are named without their folders in the cards, full path in the tooltip. Sections with no date are listed under Outside this plan. A small script marks today (aria-current="date") and greys past days using the reader's clock, so static sites and servers in another time zone agree with the reader.
  • A date counts anywhere in a section name, as cooklang-find's list_menus_for_date matches it (== Wednesday (2026-10-07) ==, = 2026-10-08 Dinner). Several sections may share a day; text after the date names the meal of the section's lines before its first meal header. A menu with a single dated day (an event menu) stays an ordinary menu.

Implementation notes

  • src/web/plan.rs: section_date (the day and meal a section name gives), build_plan_view (sorts the builder's MenuSections into days and meals with the menu API's is_meal_header rule, or None under two dated days), plan_starter (what the form writes, from a PlanFrame the form fills).
  • extract_date / is_meal_header / extract_meal_type / extract_time move from server::handlers::menus to web::menus, since the calendar is also built for static sites; the API handler imports them unchanged.
  • templates/menu.html: the line rendering (duplicated for one-item and multi-item lines) is now one askama macro, menu_item, used by the section cards and the day cards; section_card renders a section.
  • NewKind::Plan; the plan's fields are one #[serde(flatten)] struct shared by the form post and the page query, so an error redirect can bring them back. new_page_error takes the query to go back with instead of the kind.
  • chrono's unstable-locales feature names weekdays and months (Mer. 7 oct.).
  • New strings in all 9 locales.
  • docs/server.md: a "Meal plans" section.

Not in this PR (steps 2 and 3 of the proposal): editing inside the calendar, a range of days to the shopping list, a menu as a day's meal.

Screenshots

Desktop (en-US) Desktop (fr-FR)
planner planner fr
Phone (opens at today) New Meal Plan
form

Tests

  • Unit (web::plan): dates anywhere in a section name, the two-day threshold, a Wednesday start's blank cells (Monday- and Sunday-first), weeks without a section left out, sections merged by date and meal, meal slots and their order, undated sections, localised day headings, a new plan reading back with its days.
  • Integration (tests/new_menu_test.rs): the created file, French names, every error keeping the form's choices, the calendar page (including a = YYYY-MM-DD Dinner section), a menu with one dated day unchanged, the form and the listing button.
  • Playwright (tests/e2e/meal-plan.spec.ts): create through the form (shortcuts, preview), Sunday-first columns, today and past days, stacked on a phone, axe on the calendar and the form.
  • cargo fmt, cargo clippy --all-targets (also --no-default-features), cargo test all clean. Full chromium Playwright run at dd68344: 250 passed, 5 skipped; recipe-scaling › should send the scale when adding to shopping list failed once and passed on re-run (intermittent on main too).

🤖 Generated with Claude Code

A meal plan is a `.menu` whose frontmatter frames it in time:

    plan:
      start: 2026-10-07
      days: 10
      meals: [Breakfast, Lunch, Dinner]

What is eaten each day stays in dated sections (`== Wednesday
(2026-10-07) ==`), so the shopping list, the Today's menu banner,
`cook shopping-list` and other Cooklang apps read a plan like any menu.

- New Meal Plan (`/new?kind=plan`), beside New Menu: any first day,
  1 to 62 days, meals and servings. The file gets a section a day with
  an empty bullet under each meal, day and meal names in the page's
  language. An error sends the form back with its choices.
- A menu with a `plan:` block shows one card a day, in weekday columns
  from md up (Sunday first for en-US and ja-JP) and stacked on a phone.
  Each planned meal has a slot even when empty; sections with no date,
  or outside the plan, are listed under "Outside this plan". The page
  script marks today and the days gone by against the reader's clock.
- The menu page's line rendering is one askama macro, shared by the
  section cards and the day cards.
- `extract_date` / `is_meal_header` / `extract_meal_type` move to
  `web::menus` so the static build can use them.
- chrono's `unstable-locales` names weekdays and months.

Part of cooklang#385: editing inside the planner and adding a range of days to
the shopping list are left for follow-ups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst marked this pull request as ready for review October 2, 2026 19:22
@LeMyst

LeMyst commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

What do you think about @dubadub ?

@LeMyst
LeMyst force-pushed the feat/meal-planner branch from 27498cc to 1561386 Compare October 2, 2026 19:27
@dubadub

dubadub commented Oct 3, 2026

Copy link
Copy Markdown
Member

What do you think about @dubadub ?

It looks truly amazing! The only thing I'm not convinced that we need to add this extra plan block in metadata. Information from dated sections should be enough to render this calendar, or I might be missing something?

I made menus as first class citizens in cooklang-find and we can get list of all dates and map them to calendar.

What do you think @LeMyst?

@dubadub

dubadub commented Oct 3, 2026

Copy link
Copy Markdown
Member

The resistance I have with that extra plan block in metadata is because then we need to add to the spec so all apps implement that similar way, while dated sections already there.

LeMyst and others added 3 commits October 3, 2026 19:32
Drop the `plan:` frontmatter block: dated sections already say which days
a menu covers, and every Cooklang app reads them, so the calendar needs
nothing the spec does not have.

- A menu with sections on two days or more shows as a calendar, from its
  first dated day to its last. A day with no section still gets a cell;
  a week with none is left out.
- Every day offers the meals the plan's days name, in the order they
  first appear.
- A date counts anywhere in a section name, as cooklang-find's
  `list_menus_for_date` matches it, so `= 2026-10-08 Dinner` is a day too;
  the text after the date names the meal of the section's first lines.
- The new-plan form keeps its fields but writes the sections only, and
  asks for 2 to 62 days.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With a plan whose first day has only `Dinner:` and a later one
`Lunch:` then `Dinner:`, every day offered Dinner before Lunch: a meal
no earlier day named went last. It now goes after the meal it follows
on its day, or, as that day's first, before the next meal the day has.

`meal_slots` takes plain meal names, so the plan's text can be read in
the same order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The menu page drops sections with nothing in them, so a plan whose last
days were bare headings (`== Friday (2026-10-09) ==`) ended at the last
day with something planned. Dated sections are now kept while the
calendar is laid out, and dropped as before when the menu is not a
plan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst merged commit 27006e1 into cooklang:main Oct 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants