Repository navigation
feat(ui): scale a recipe by servings when it declares them - #565
Merged
Merged
Conversation
On a recipe with a whole number of `servings`, the recipe page's stepper now counts servings: it starts at the recipe's own servings, goes from half a serving up with no upper limit, and navigates to `?servings=N`. The factor is `N / servings`. The servings pill and the print header show the chosen servings, and "add to shopping list" sends the factor. Recipes without servings, or with servings that are not a whole number (`4-6`, `1.5`, `0`), keep the scale multiplier. `?scale=` still works everywhere and, on a recipe with servings, shows as the servings it gives, so menu links keep their meaning; `?servings=` wins over it. The pill is set from the stepper rather than the scaled metadata: `Recipe::scale` rounds `servings` to a whole number, so half of a 4-serving recipe would have read 1. Closes cooklang#564 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A menu that declares `servings` now has the same servings stepper as a
recipe: it starts at the menu's servings, navigates to `?servings=N`,
and "add all to shopping list" sends the factor. A menu without
servings keeps the scale multiplier.
A menu links each recipe it references by servings when that recipe
declares them (`?servings=10` for `{10%servings}` of a 2-serving
recipe), and by its factor otherwise (`?scale=`), so the link opens the
stepper at the value it counts in. A x1 reference keeps a plain link.
The recipe page now takes any positive `?servings=`, as it does
`?scale=`: a menu at x0.1 links to 0.4 of a 4-serving recipe. The half
a serving floor stays the stepper's, for what people type.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Scaling a recipe away from its own servings multiplies the quantities, but cooking times, pan sizes and seasoning do not always follow. Next to the servings pill, a recipe or menu scaled to other servings now shows "Written for 4 servings", with a hint saying what may need adjusting; it links back to the original servings. Nothing shows at the recipe's own servings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A recipe or menu without servings, scaled away from x1, now gets the same reminder as one scaled by servings: "x1.5 of the original recipe", with the hint about times, pan sizes and seasoning, linking back to the original. A recipe with no metadata at all gets a row for it, since the metadata row is not rendered then. `Tr::tf` passes a factor to Fluent as `$factor`, formatted like the menu badges (`1.5`, `0.333`). Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
marked this pull request as ready for review
September 28, 2026 18:12
This was referenced Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #564
What changes
On a recipe that declares a whole number of
servings, the recipe page's stepper counts servings instead of a raw multiplier:servings: 4→ Servings: 4), not at 1.max="200"is gone there).?servings=6; the factor applied to quantities is6 / 4 = 1.5.6 servings,0.5 servings) instead of1.5x.When the page is scaled away from the recipe's own servings, a badge next to the servings pill says what it was written for (📖 Written for 4 servings). Its hint explains that quantities are scaled but cooking times, pan sizes and seasoning may need adjusting, and it links back to the original servings. Nothing shows at the recipe's own servings. Menus with servings get the same badge. A recipe or menu without servings, scaled by the multiplier, gets the same reminder as a factor (📖 ×1.5 of the original recipe), linking back to ×1; a recipe with no metadata at all gets a row of its own for it.
Recipes without
servings, or whoseservingsis not a whole number (4-6,1.5,0: cooklang only reads au32), keep today's Scale multiplier, unchanged.Compatibility with
?scale=?scale=keeps working on every recipe. On one that declares servings it applies the same factor and shows it as the servings it gives: the menu links from #561 (Easy Pancakes?scale=5) open at Servings: 10. When both are present,?servings=wins. A?servings=on a recipe without servings is ignored.?servings=that is zero, negative or not finite falls back to the recipe's default (or to?scale=). Any positive value is taken as is, like?scale=: the half-a-serving floor belongs to the stepper (what people type), while a menu can link below it (menu at ×0.1 → 0.4 servings of a 4-serving recipe). As with #561's scale field, the stepper then takes that value as its minimum andstep="any", and the −/+ buttons and+/-/[/]shortcuts keep #561's 0.5 grid.Menus
servingsgets the same Servings stepper (2 Day Plan,servings: 2→ Servings: 2,?servings=4doubles every reference). "Add all to shopping list" sends the factor. A menu without servings keeps the multiplier.@./Breakfast/Easy Pancakes{10%servings}(a 2-serving recipe) links to?servings=10rather than?scale=5, and a recipe without servings keeps?scale=. The ×factor badge next to the link is unchanged, and a ×1 reference still has a plain link. Every reference now looks up its recipe (memoised per page), since even a{}reference needs to know whether its target counts servings.Implementation notes
resolve_servings(src/web/builders.rs) reads the recipe's servings before scaling, then applies one factor.util::parse_recipe_from_entryis split so the builder can parse without scaling first.Recipe::scalerewritesservingsrounded to a whole number, so half of a 4-serving recipe would have read1.#scale/#servings);adjustScalefinds either, and treats a missingmaxas unbounded.cook build web) is unchanged (no stepper, plain.htmllinks); the menu JSON API still reports factors; the CLIrecipe.cook:Nsyntax stays a multiplier (out of scope, see feat(ui): scale a recipe by number of servings when it declares them #564).aria-decrease-servings/aria-increase-servings,recipe-written-for(plural),recipe-scaled-from-originaland their hints in all 8 locales; the label reuseslabel-servings. The badges are.metadata-original(accent-tintedmetadata-pill), with-servings/-scalevariants.Tr::tfpasses a factor to Fluent as$factor, formatted like the menu badges.Tests
builders.rs(servings_tests): default, factor, the "written for" badge (absent at the original servings, singular, link back), the multiplier badge (with and without metadata, once, not on a recipe with servings), half a serving, no ceiling, below-the-floor values from menus,servingsoverscale,?scale=links, unusable values, recipes without/with non-integer servings, menu stepper with and without servings, and menu links by servings or scale.menu_api_test.rs: the HTML-vs-API agreement test reads both?servings=and?scale=links, checks which recipe gets which, and skips the scaled menu's link to itself.recipe-scaling.spec.tsrewritten to cover both modes explicitly (it used to click the first recipe and silently pass when#scalewas missing). Shopping-list calls are intercepted to check the factor sent.menu-scale.spec.ts(feat(ui): open a menu's recipes at the scale the menu asks for #561) updated: menu links to Easy Pancakes and lamb-chops now carry?servings=; the grid-step cases moved to a recipe without servings, plus one servings case; new cases for the menu's own servings stepper, its effect on links, and the factor sent by "add all to shopping list".cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test: clean. Full Playwright chromium suite: 243 passed, 5 skipped, 0 failed.🤖 Generated with Claude Code