Skip to content

feat(ui): open a menu's recipes at the scale the menu asks for - #561

Merged
LeMyst merged 2 commits into
cooklang:mainfrom
LeMyst:feat/menu-scale-links
Sep 28, 2026
Merged

LeMyst merged 2 commits into
cooklang:mainfrom
LeMyst:feat/menu-scale-links

Conversation

@LeMyst

@LeMyst LeMyst commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #560.

Problem

A menu shows each recipe reference with the factor it resolves to: @./Risotto{2%servings} for a 4-serving risotto reads Risotto (×0.5). The menu API and "add to shopping list" use the same factor. The link, though, opened the recipe at ×1, so the quantities on the recipe page, and what its "add to shopping list" added, did not match the menu.

Change

  • Menu links carry the factor. templates/menu.html (both reference branches) appends ?scale={factor} when the factor is not 1. The recipe page already takes ?scale=. A ×1 reference keeps a plain link.
  • Static exports are unchanged. cook build web pages cannot scale from a query string, so in static_mode the links stay plain .html. The badge still shows the factor.
  • Formatted factors. A new askama filter, scale_factor, rounds to 3 places and drops trailing zeros, for the badge and the link alike: ?scale=0.333, (×0.333). The badge used to print the raw f64, e.g. (×0.3333333333333333).
  • The recipe page's scale field takes the factor it was opened at. It was min="0.5" step="0.5", so a recipe opened at ×0.25 or ×0.333 showed an invalid field. Now step="any", and min drops to the page's scale when that is below 0.5.
  • Scale steps land on multiples of 0.5 (adjustScale in static/js/keyboard-shortcuts.js, used by the −/+ buttons and the +/-/[/] shortcuts). A scale on the grid moves by the full step. One between steps, such as 1.667 from a menu, stops at the nearest step in that direction: + gives 2, − gives 1.5. The field's minimum still wins below the first step, so − at ×0.25 stays at 0.25. Previously it clamped and then rounded to 0.1, which moved it up to 0.3.

Tests

  • tests/menu_api_test.rs: html_menu_page_agrees_with_the_menu_api also reads each link's ?scale= and checks it equals the badge (none for ×1), at menu scale 1 and 2. Its regex used to match only links without a query string.
  • tests/build.rs: static_menu_links_carry_no_scale. In the seed's exported "2 Day Plan", the ×5 badge is still shown and no link has ?scale=.
  • src/web/templates.rs: unit tests for scale_factor.
  • tests/e2e/menu-scale.spec.ts:
    • The ×5 pancakes link opens the recipe at scale 5, and the ×1 link has no query string.
    • At menu ×0.25, lamb chops open at 0.25, the field is valid, "−" keeps 0.25 and "+" goes to 0.5.
    • From 1.667, "+" gives 2 and "−" gives 1.5; from 1.5, "+" gives 2 and "−" gives 1; ] from 1.667 gives 2.5.

Checked locally:

  • cargo fmt --check: clean.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean.
  • cargo test: all suites pass.
  • npx playwright test --project=chromium: 229 passed, 5 skipped.

🤖 Generated with Claude Code

@LeMyst
LeMyst force-pushed the feat/menu-scale-links branch from 1c6bd1c to 587b8d3 Compare September 28, 2026 05:01
A menu reference such as `@./Risotto{2%servings}` is shown with its
factor (×0.5), the one the menu API and "add to shopping list" use, but
its link opened the recipe at ×1. Menu links now carry that factor as
`?scale=`; a ×1 reference keeps a plain link. Static exports keep plain
`.html` links too, since a static page cannot scale from a query string.

The factor is formatted by a new `scale_factor` filter instead of
printing the raw f64: 6 places in the URL, which keeps quantities exact
after the recipe page's own rounding, and 3 in the badge, which used to
read like `×0.3333333333333333`.

The recipe page's scale field takes any factor it is opened at: `step`
is `any`, and `min` drops below 0.5 when the scale does. The −/+ helper
now rounds before it clamps, so − on a recipe at ×0.25 stays at 0.25
instead of rounding up to 0.3.

Closes cooklang#560

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A recipe opened from a menu can start between steps, at a scale such as
1.667. The −/+ buttons and the +/-/[/] shortcuts now land on the 0.5
grid: a scale on it moves by the full step, one between steps stops at
the nearest step in that direction (+ gives 2, − gives 1.5). The field's
minimum still wins when it sits below the first step.

Menu links now carry the factor with 3 decimals, like the badge next to
them; 6 was more precision than a recipe page needs. `scale_factor`
loses its `places` argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst
LeMyst marked this pull request as ready for review September 28, 2026 10:50
@LeMyst
LeMyst merged commit 4c46135 into cooklang:main Sep 28, 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.

feat(ui): open a menu's recipes at the scale the menu asks for

1 participant