Repository navigation
feat(ui): random recipe button scoped to the current folder - #554
Merged
Merged
Conversation
A dice icon next to "New recipe" on the listing redirects to a random
.cook recipe from the folder being browsed and its subfolders, through
GET /random and GET /random/{*path}. Menus are never picked; the button
is hidden when there is nothing to pick and on static sites, which have
no server to redirect.
The per-segment URL encoder moves from the sitemap to util so the new
redirect can share it: axum's Redirect refuses a non-ASCII Location.
Closes cooklang#544
Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
marked this pull request as ready for review
September 27, 2026 00:43
dubadub
approved these changes
Sep 27, 2026
dubadub
left a comment
Member
There was a problem hiding this comment.
Interesting idea, lets give it a try
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 #544
What
A dice icon button next to New recipe on the recipe listing opens a random recipe from the folder being browsed, subfolders included. On
/the pick spans the whole collection; on/directory/Mainsit only picks fromMains/and below (e.g.Mains/Pasta/…).How
GET /randomandGET /random/{*path}(src/server/ui.rs) validate the folder withis_safe_relative_path, walk it withcooklang_find::build_tree, pick one.cookrecipe and answer303 See Otherto/recipe/<path>. No recipe list is sent to the page..menu) are never picked.404, an unsafe path400, and a missing folder404.Locationis percent-encoded per segment, because axum'sRedirectrefuses non-ASCII headers (e.g.Crème brûlée).build_recipes_templatesets arandom_recipe_urlonly when the subtree holds at least one.cookrecipe. The template renders an.icon-btnwith a translatedaria-label/titleonly when that URL is set, so the button is hidden for empty or menu-only folders.cook build web) — the button is hidden: there's no server to redirect, and embedding every recipe path in each listing page felt heavier than this nice-to-have deserves. A client-side pick could be a follow-up.random-recipeadded to all 8 locales.build/sitemap.rsmoved toutil::encode_url_pathso the sitemap and the new route share it.fastrand(already in the lock file transitively) becomes an optional dependency of theserverfeature.Tests
tests/random_recipe_test.rs(spawnscook serverthroughcommon::with_isolated_config) checks that:/random/…answers 404;..%2Fis refused (400) and a missing folder gives 404.tests/build.rs: the static index has no random button.tests/e2e/navigation.spec.ts: clicking the dice on/directory/Breakfastlands on a/recipe/Breakfast/…page.cargo fmt,cargo clippy --all-targets(no warnings) andcargo testpass. The full chromium Playwright project also passes locally.🤖 Generated with Claude Code