Repository navigation
feat(ui): open a menu's recipes at the scale the menu asks for - #561
Merged
Merged
Conversation
LeMyst
force-pushed
the
feat/menu-scale-links
branch
from
September 28, 2026 05:01
1c6bd1c to
587b8d3
Compare
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]>
LeMyst
force-pushed
the
feat/menu-scale-links
branch
from
September 28, 2026 10:10
587b8d3 to
7228a6c
Compare
7 tasks
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
marked this pull request as ready for review
September 28, 2026 10:50
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 #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
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.cook build webpages cannot scale from a query string, so instatic_modethe links stay plain.html. The badge still shows the factor.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 rawf64, e.g.(×0.3333333333333333).min="0.5" step="0.5", so a recipe opened at ×0.25 or ×0.333 showed an invalid field. Nowstep="any", andmindrops to the page's scale when that is below 0.5.adjustScaleinstatic/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_apialso 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 forscale_factor.tests/e2e/menu-scale.spec.ts:]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