Skip to content

feat(ui): scale a recipe by number of servings when it declares them #564

Closed

Description

@LeMyst

Summary

On the recipe page, let people choose how many servings to cook instead of a raw multiplier, whenever the recipe declares servings. Recipes without servings keep today's scale control.

Current behaviour

templates/recipe.html shows a Scale stepper that is always a multiplier:

  • defaults to 1 (RecipeQuery.scale.unwrap_or(1.0) in src/server/ui.rs)
  • min="0.5", max="200", step="0.5", and the − / + buttons move it by 0.5
  • navigates to /recipe/<path>?scale=<factor>
  • the print header reads Scale: 1.5x

For a recipe with servings: 4, cooking for 6 means working out 1.5 by hand, and the 👥 pill keeps saying 4 servings.

Proposal

Recipe declares a numeric servings (e.g. servings: 4)

  • The stepper is labelled Servings (people) instead of Scale.
  • Default value = the recipe's servings (4 here), not 1.
  • Accepted range: 0.5 (half a serving) up to any value. No max; step="0.5", and the − / + buttons still move by 0.5.
  • The factor applied to quantities is chosen / servings (6 servings on a 4-serving recipe → 1.5).
  • The 👥 servings pill and the print header show the chosen number of servings (6 servings), not 1.5x.
  • Add to shopping list sends the derived factor, so the list matches what is shown.

Recipe has no servings, or it is not a single number

This covers a missing key, text such as servings: 4-6, and fractional values: the cooklang API only exposes u32, see RecipeInfo.default_servings in src/util/menu_scale.rs.

In all of these cases nothing changes: the current Scale multiplier, defaulting to 1.

URL

Proposed: a ?servings=6 query parameter on recipe pages that declare servings. ?scale= stays accepted everywhere, so existing links keep working. That includes the menu links from #560 / #561, bookmarks, and ?scale= on recipes without servings. When both are present, servings wins. An alternative is to keep ?scale= as the only parameter and convert only in the UI. That is open for discussion.

Edge cases

  • ?servings= below 0.5, zero, negative or non-numeric: clamp or fall back to the recipe default, as goToScale already does for scale.
  • Very large values: no UI cap, but quantities must still render sanely (no overflow, no NaN).
  • The static export (static_mode) hides the stepper today; unchanged.

Out of scope

  • CLI recipe.cook:N syntax (cook recipe, cook shopping-list): still a multiplier. A --servings flag could be a follow-up.
  • Menus: they already scale references with {N%servings}.

Acceptance criteria

  • Recipe with servings: 4: the stepper shows Servings = 4 by default. Setting 6 scales every quantity ×1.5, and the pill and print header show 6.
  • 0.5 is accepted (half a serving). There is no upper limit in the input.
  • Recipe without numeric servings: the Scale multiplier behaves exactly as today.
  • Existing ?scale= links still render at the same factor.
  • Add to shopping list uses the derived factor.
  • New UI strings translated in every locale.
  • Playwright coverage in recipe-scaling.spec.ts for both modes.

Activity

  1. added a commit that references this issue on Oct 3, 2026
    1e2978f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions